2

テーブルセルビューにxml解析データを表示しているときに、このセマンティックの問題が発生しました。アプリケーションは正常に実行されますが、任意の行を選択すると、アプリが詳細表示され、アプリがクラッシュします。plsは助けます!!!

この行 の3番目のケースでセマンティックの問題が発生します

cell.textLabel.text = aBook.bookID;

アプリコード:

- (UITableViewCell *)tableView:(UITableView *)tv 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

  static NSString *CellIdentifier = @"Cell";

  UITableViewCell *cell = 
    [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                   reuseIdentifier:CellIdentifier] autorelease];
  }

  switch (indexPath.section) {
    case 0:
      cell.textLabel.text = aBook.name;
      break;
    case 1:
      cell.textLabel.text = aBook.author;
      break;
    case 2:
      cell.textLabel.text = aBook.price;
      break;
    case 3:            
      cell.textLabel.text = aBook.bookID;
      break;
  }

  return cell;
}
4

2 に答える 2

3

おそらく、aBook.bookID変数はNSIntegerです。これをNSStringに変換するには、次を使用します。

case 3:            
    cell.textLabel.text = [NSString stringWithFormat:@"%i", aBook.bookID];
    break;
于 2012-06-01T10:08:12.600 に答える
2

あなたのケース3はあなたのbookIDに依存します

intの場合

cell.textLabel.text = [NSString stringWithFormat:@"%d",aBook.bookID];

NSIntegerの場合

 cell.textLabel.text = [NSString stringWithFormat:@"%i",aBook.bookID];

文字列にint値を提供しているため

于 2012-06-01T10:10:30.607 に答える