Possible Duplicate:
sectioned UITableView sourced from a pList
I am having a hard time trying to set the text label of the cell to the values of the strings in my plist. The app crashes on cell.textlabel.text = [array objectAtIndex:indexPath.row];. I’m pretty sure everything else is good, just don’t know that last part. Thanks in advance.
Here is my plist:
Root - Array
Item 0 - Dictionary
Key 0 - Array
Item 0 - String - Value 0
Key 1 - Array
Item 1 - String - Value 1
Here are my tableview data source methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _objects.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSDictionary *dict = [_objects objectAtIndex:section];
return [dict.allValues count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSArray *array = [_objects objectAtIndex:indexPath.section];
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
well the structure of your
_objectis not clear. I am assuming it refers toItem 0 - Dictionaryin the plist.in
numberOfRowsInSection:you refer to it as a dictionary:while in
cellForRowAtIndexPath:you refer to it as an array:anyway, if my assumption is correct then change the
cellForRowAtIndexPathcode to the following:hope this helps.
EDIT:
well you can restructure your plist to achieve that. You basically just get rid of the
dictionarylevel.. try something like this: