I am having some trouble with objective c on iPhone. I have this method as shown below, but when I run this piece of code, it does not show any results in my table. I think it’s the number of sectionInTableView method which return me nothing when I call
return [listOfItems count];
when I change it to [_patientInfos count]; it works.
- (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];
}
It seems you’ve forgot to create the
listOfItemsarray. You should create it usingbefore you add any object to the array. If you are not creating the object, it will be
niland any message you send tonilwont take any effect.