0

1 つの tableView に 2 つの異なる配列を表示しようとしています。「years」配列を文字列として宣言し、「mount」配列を整数として宣言しました。年数 例: 2012, 2013 .... 155888, 151768 アプリケーションを build7run すると、結果は次のようになります: (数字が 16 ずつ減っているように見えます)

 Remaining Amount On  

2012: 80912864
2013: 79047056
2014: 79046640
2015: 79046640
2016: 79051632
...
2020: 80928544

「年」配列は文字列として機能しますが、「金額」である整数配列は機能しません。cell.text= 行で整数の書式設定を行っていることは間違いありません。この問題の解決に役立てていただければ幸いです よろしくお願いします

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

static NSString *CellIdentifier = @"remainingAmountOn";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

NSUInteger row = [indexPath row];
**cell.text =** [NSString stringWithFormat:@"%@   %d", [years objectAtIndex:row],

[NSNumber numberWithInt:[amount objectAtIndex:row]]];

return cell;

}

4

1 に答える 1

1
[NSNUmber numberWithInt:someInt]

NSNumber オブジェクトを返し、%@ でフォーマットする必要があります。

または、NSNumber ビットをスキップして、%d で int を使用します。

現時点では、2 つを混在させています。

于 2011-03-31T21:53:38.453 に答える