2012-01-15 47 views
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *theCell=[UITableViewCell alloc]; 
    theCell=[theCell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 

     NSLog(@"%i",[table count]); 

     theCell.textLabel.text=[table objectAtIndex:[indexPath row]]; 

    return theCell; 
} 

有插入文件Values.plist三個值,它們填充在功能viewDidLoad中在我的iPhone應用程序崩潰時我使用表格視圖

" theCell.textLabel.text=[table objectAtIndex:[indexPath row]]; " 
But the line "NSLog(@"%i",[table count]);" works and shows me 3 
please help . 
的NSArray的「表」(),但我的應用程序崩潰
+0

這d幫助發佈應用程序崩潰時得到的錯誤消息。看一下控制檯來找到它。堆棧跟蹤也很有幫助。 – Caleb 2012-01-15 06:36:00

+0

所以最新的錯誤信息?確保你的數組中有字符串值。 – 2012-01-16 15:33:29

回答

0

請注意以下問題:

1)確保NSArray有值,即它被填充。

2)相關搜索NSLog(@"%d",[table count]);

我想你應該更好地與%d而不是%i去。

希望這可以幫助你。

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.textLabel.text = [table objectAtIndex:indexPath.row]; 
     return cell; 
    } 

作爲一個方面說明,這是ARC實現。如果你不使用ARC只需添加一個自動釋放:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autoRelease]; 

還請確保您的數據源numberOfSections設置正確:

return 1; 

和numberOfRows設置爲數組:

return [table count];