开发者

Populating information in tables using NSDictionary

开发者 https://www.devze.com 2023-03-12 04:45 出处:网络
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 section

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:(UITableV开发者_运维问答iew *)tableView
{
    if (searching)
        return 1;
    else
        return [listOfItems count];
}


It seems you've forgot to create the listOfItems array. You should create it using

listOfItems = [[NSMutableArray alloc] init];

before you add any object to the array. If you are not creating the object, it will be nil and any message you send to nil wont take any effect.

0

精彩评论

暂无评论...
验证码 换一张
取 消