I'm trying to grab avalue from a UIPicker which is populated with round numbers, integers pulled from and NSMutableArray. I'm trying to convert the pulled values to an actual int.
I tried this in the .m:
int pickednumber;
......
-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSString *numbers = [arrayNumbers objectAtIndex:[pickerView selectedRowInComponent:0]];
pickednumber = [NSString stringWithFormat:@"%d", numbers];
NSLog(@"Picked number %@ ", numbers);
}
I get the error in the pickednumber = line: Incompatible pointer to integer conversion assigning to 'int' from 'id'. What am i doing wrong?
Message was edited by Sounddesigner on 3/8/12 at 3:05 PM
NSString
has a convinience method to get integer value of a text
do this
pickednumber = [numbers intValue];
NSLog(@"Picked number %d ", numbers); // not %@ ..%@ is for objects .. not int
To convert integer to NSString:
NSString *string = [NSString stringWithFormat:@"%i",integerNumber];
To convert NSString to int:
int number = [string integerValue];
NSString *intString = [NSString stringWithFormat:@"%d", myInt];
http://forums.macrumors.com/showthread.php?t=448594
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With