cellForRowAtIndexPath(需要在索引路径中使用一个字符串和一个整数值)
亲爱的大家
我试图在一个tableView中显示两个不同的数组。
我将“years”数组声明为字符串,将“amount”数组声明为整数。
年数量
例如:2012年,2013年...... 155888,151768
当我构建7运行应用程序时,结果如下:
(看起来它将数字递减16)
Remaining Amount On
2012:80912864
2013:79047056
2014:79046640
2015:79046640
2016年:79051632
...
2020:80928544
“year”数组的工作原理是字符串,但是“amount”的整数数组不能。
我很确定我在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;
}
没有找到相关结果
已邀请:
1 个回复
抚驰
返回一个NSNumber对象,应使用%@格式化。 或者,跳过NSNumber位,只使用带有%d的int。 目前,你正在混合两者。