Reputation: 117
I've been trying to put the value of my array in my table view cells, it's multidimensional array how should i do it?
here's a parser class
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"subsidiary"])
{
NSLog(@"%i", [app.infoarray count]);
[app.listArray addObject:app.infoarray];
[app.infoarray removeAllObjects];
}
else
{
if ([elementName isEqualToString:@"countryname"])
{
temp = currentElementValue;
}
if ([elementName isEqualToString:@"name"])
{
theList.name = currentElementValue;
[app.infoarray addObject:theList.name];
}
if ([elementName isEqualToString:@"address"])
{
theList.address = currentElementValue;
[app.infoarray addObject:theList.address];
}
the code below is the mainviewcontroller
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
theList.countryname = [app.listArray objectAtIndex:0];
cell.textLabel.text= theList.countryname; ////<<WHAT SHOULD I DO HERE?
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
I just want the cell.textlabel to display the country name I'm just new in objective-c i hope someone can help me
Upvotes: 0
Views: 2222
Reputation: 107231
This line makes issue:
theList.countryname = [app.listArray objectAtIndex:0];
Change it to:
theList.countryname = [[app.listArray objectAtIndex:indexPath.row] objectAtindex:0];
Upvotes: 1
Reputation: 1088
Just try
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
theList.countryname = [app.listArray objectAtIndex: indexPath.row];
cell.textLabel.text= theList.countryname;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Upvotes: 1