【发布时间】:2017-07-12 13:44:16
【问题描述】:
这里,m 在引用 tableview 时尝试对数组进行排序,但在刷新 tableview 时应用程序崩溃。
由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[_PFArray sortUsingDescriptors:]:发送到实例的无法识别的选择器 0x6080000550c0'
@interface TableViewController () {
NSMutableArray *returnArray;
}
@end
- (void)viewDidAppear:(BOOL)animated {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate manageObjectContext];
NSError *error = nil;
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Resgistration" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDescription];
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"Unique",nil]];
returnArray = [[NSMutableArray alloc] init];
returnArray = [context executeFetchRequest:request error:&error];
for(Resgistration* reg in returnArray) {
NSLog(@"%@", reg);
NSLog(@"%@", reg.roshan);
}
[self.tableView reloadData];
UIColor *gray = [UIColor colorWithRed:234/255.0 green:234/255.0 blue:234/255.0 alpha:1.0];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Please Wait"];
[refreshControl setBackgroundColor:gray];
[refreshControl addTarget:self action:@selector(sortArray) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
- (void)sortArray
{
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(localizedStandardCompare:)];
NSMutableArray *sortDescriptior = [[NSMutableArray alloc] initWithObjects:sort, nil];
[returnArray sortUsingDescriptors:sortDescriptior]; // crash the app
[self.tableView reloadData];
[self.refreshControl endRefreshing];
}
请帮我解决这个问题。谢谢。
【问题讨论】:
-
看来你的returnArray是
PFArray类的类型请检查一下,我认为这个类PFArray可能没有这个方法 -
retutnrArray 是 NSMutableArray 那么 PFArray 是什么?
-
请张贴
returnArray声明 -
问题是编辑请检查。
-
请贴出你所有涉及returnArray的代码