我正在从数组填充pickerView。它可以加载到页面中。但是,当您在第11个选项中滚动选择器时,它会因[NSNull rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x19fc50490
错误而崩溃。
我真的不知道下一步该尝试什么,并会对任何建议表示感谢:
这是我的代码:
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
return _actnames.count;//THis logs as 30 as there are 30 possibilities
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
NSLog(@"before crash"); //last line to display before crash
return _actnames[row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
_selectedActName = ([_actnames objectAtIndex:row]);
}
最后一种方法似乎是崩溃的方法。如上所述,当您选择第11个项目时它会崩溃,尽管有30个。
感谢任何想法。
更新
This is method that pulls actnames from core data:
- (id) getActNames{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Activities"];
fetchRequest.resultType = NSDictionaryResultType;
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"created" ascending:NO];
[fetchRequest setSortDescriptors:@[sort]];
NSError *error = nil;
self.managedObjectContext = [Model sharedInstance].managedObjectContext;
NSArray *results = [self.managedObjectContext executeFetchRequest:fetchRequest
error:&error];
NSMutableArray * actnames = [[results valueForKey:@"actname"] mutableCopy];
return actnames;
}