【问题标题】:cellForRowAtIndexPath (need to use one string and one integer values in the indexpath)cellForRowAtIndexPath(需要在indexpath中使用一个字符串和一个整数值)
【发布时间】:2011-03-31 21:34:57
【问题描述】:

亲爱的 我试图在一个 tableView 中显示两个不同的数组。 我将“years”数组声明为字符串,将“amount”数组声明为整数。 年金额 例如:2012、2013 .... 155888、151768 当我 build7run 应用程序时,结果如下: (看起来它减少了 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;

}

【问题讨论】:

    标签: objective-c uitableview row nsindexpath nsuinteger


    【解决方案1】:
    [NSNUmber numberWithInt:someInt]
    

    返回一个 NSNumber 对象,应该用 %@ 格式化。

    或者,跳过 NSNumber 位,只使用带有 %d 的 int。

    目前,您正在将两者混为一谈。

    【讨论】:

      猜你喜欢
      • 2014-10-27
      • 2020-11-02
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多