0

Dear all I am trying to display two different arrays in one tableView. I declared "years" array as strings and "amount" array as integers. years amount e.g: 2012, 2013 .... 155888, 151768 When I build7run the application the outcome is like below: (it looks like it decrements numbers by 16)

 Remaining Amount On  

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

The "year" array works as it is string but the integer array which is "amount" does not. I am pretty sure that I am doing wrong in the cell.text= line with the integer number formatting. I would be very happy if you could help to solve this problem Thanks in advance

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

}

erguvani
  • 81
  • 1
  • 3
  • 7

1 Answers1

1
[NSNUmber numberWithInt:someInt]

returns an NSNumber object and should be formatted with %@.

Alternately, skip the NSNumber bit and just use the int with %d.

At the moment, you're mixing the two.

Terry Wilcox
  • 9,010
  • 1
  • 34
  • 36