你好善良的灵魂,
我在iphone上的目标c确实遇到了一些麻烦。我有这个方法,如下所示..但是当我运行这段代码时,它不会在我的表中显示任何结果。我认为它的sectionInTableView方法的数量,当我调用
时,它没有返回任何内容return [listOfItems count];
当我将其更改为[_patientInfos count];
时,它可以正常工作。
请帮忙,因为我真的被卡住了,我根本找不到错误。我在这里是一个菜鸟,需要一些紧急帮助=(
- (void)viewDidLoad
{
[super viewDidLoad];
self.patientInfos = [PatientDatabase database].patientInfos;
self.title = @"Patients";
NSArray *patientsToLiveInArray = [NSArray arrayWithObject:_patientInfos];
NSDictionary *patientsToLiveInDict = [NSDictionary dictionaryWithObject:patientsToLiveInArray forKey:@"Patients"];
[listOfItems addObject:patientsToLiveInDict];
copyListOfItems = [[NSMutableArray alloc] init];
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (searching)
return 1;
else
return [listOfItems count];
}
答案 0 :(得分:1)
您似乎忘了创建listOfItems
数组。您应该使用
listOfItems = [[NSMutableArray alloc] init];
在将任何对象添加到数组之前。如果您没有创建对象,它将是nil
,并且您发送给nil
的任何消息都不会产生任何效果。