【发布时间】:2017-02-17 02:46:28
【问题描述】:
当执行 reloadData 方法时,我想随机化/随机化 NSMutableArray 中项目的顺序。我尝试了以下方法,但控制台不断向我抛出以下错误:
由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[__NSArrayI exchangeObjectAtIndex:withObjectAtIndex:]:发送了无法识别的选择器 到实例 0x1748b2c60'
知道为什么会这样吗?我被难住了。
ViewController.h
@property (strong, retain) NSMutableArray *neighbourData;
ViewController.m
- (void)reloadData:(id)sender
{
NSMutableDictionary *viewParams = [NSMutableDictionary new];
[viewParams setValue:@"u000" forKey:@"view_name"];
[DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.neighbourData = (NSMutableArray *)responseObject;
[self.tableView reloadData];
NSUInteger count = [self.neighbourData count];
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
int nElements = count - i;
int n = (arc4random() % nElements) + i;
[self.neighbourData exchangeObjectAtIndex:i withObjectAtIndex:n];
}
NSLog(@"This is the neighbourdata %@",self.neighbourData);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", [error localizedDescription]);
}];
【问题讨论】:
标签: ios objective-c