views:

51

answers:

3

So I have an Array "myArray" with NSNumbers and NSStrings. I need them in another View so i go like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

DetailViewController *details = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
details.subjectText = [[myArray objectAtIndex:indexPath.row] objectForKey:@"subject"];

The subjectText works. But how can I get the Numbers out of it? (I actually need them as strings...) I would convert a String out of a Number like this: NSString *blah = [NSNumber intValue]. But I don't know how to set it up in the code above..

+1  A: 

try NSString *myString = [NSNumber stringValue];

JonLOo
thank you but, I have an Array and that doesn't respond to stringValue..
dav3
but you should take the NSNumber which is inside the array and then call StringValue method, something like NSString *myString= [[myArray objectAtIndex:i] stringValue]; but you have to be sure that you have an NSNumber at that index
JonLOo
A: 
[NSString stringWithFormat:@"%i",[NSNumber intValue]];

If you have other numbers than integers, you can replace intValue by floatValue, doubleValue, ... Note that in the format string you need to replace %i by the correct format specifier (%f for double, ..., full list here).

This guide is going to show you how to format NSStrings.

muffix
`%d` is decimal, ie integer represented as base 10, same as `%i` -- `%f` handles doubles
walkytalky
Thanks, I always mix them up. Edited the original answer.
muffix
A: 

or try NSString *string = [NSString stringWithFormat:@"%d", [NSNumber intValue]];

JohnnySun