2013-01-24 109 views
0

我一直試圖把我的數組的值放在我的表格視圖單元格中,這是多維數組我應該怎麼做?如何把數組元素放在一個表格視圖單元格

這裏有一個解析器類

-(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]; 
    } 

下面的代碼是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; 

} 

我只想cell.textlabel顯示國名 我在短短的新目標c我希望有人能幫助我

回答

1

試試吧

- (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; 

    } 
+0

構建成功,但它不顯示任何東西 –

+0

@ Tbt-lionArmanCapistrano:你用過tableview委託嗎? NSlog(@「%@」,[theList.countryname]); – iAppDeveloper

+0

它是空的,在List.countryname中沒有值。我該怎麼辦? –

1

此行使得問題:

theList.countryname = [app.listArray objectAtIndex:0]; 

將其更改爲:

theList.countryname = [[app.listArray objectAtIndex:indexPath.row] objectAtindex:0]; 
+0

我得到一個錯誤:(「無法識別的選擇發送到實例0x71854a0'」 –

+0

@ Tbt-lionArmanCapistrano:修復了這個問題:) –

相關問題