2012-01-15 6 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に挿入された3つの値があり、彼らは私のiPhoneのアプリケーションがクラッシュiは、テーブルビューを使用する場合

" theCell.textLabel.text=[table objectAtIndex:[indexPath row]]; " 
But the line "NSLog(@"%i",[table count]);" works and shows me 3 
please help . 
での関数のviewDidLoadでNSArrayの「テーブル」()が、私のアプリケーションのクラッシュを移入
+0

それを」 dは、アプリケーションがクラッシュしたときに表示されるエラーメッセージを投稿するのに役立ちます。それを見つけるためにコンソールで見てみましょう。スタックトレースも役立ちます。 – Caleb

+0

これでエラーメッセージは何ですか?配列に文字列値があることを確認してください。 –

答えて

0

以下の点に注意してください。

1)NSArrayに値が設定されていることを確認します。

2)また、私はあなたがより良い%dなく%iで行くべきだと思いNSLog(@"%d",[table count]);

を試してみてください。

希望すると、これが役立ちます。これはARCの実装であるサイドノートとして

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

1

これは標準的な実装です。右に設定されても、必ずあなたのdataSource numberOfSectionsを作る

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

:あなたは、ARCを使用していない場合は、単に自動解放を追加

return 1; 

とnumberOfRowsを配列に設定されています:

return [table count]; 
関連する問題