Gie*_*iel 14 int xcode nsstring ios
我试图从UIPicker中获取avalue,其中包含圆形数字,从中抽取的整数和NSMutableArray.我正在尝试将拉出的值转换为实际的int.
我在.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);
}
Run Code Online (Sandbox Code Playgroud)
我在picknumber = line中得到错误:指向整数转换的不兼容指针从'id'分配给'int'.我究竟做错了什么?
消息由Sounddesigner于3月8日下午3:05编辑
Shu*_*ank 96
NSString有一个方便的方法来获取文本的整数值
做这个
pickednumber = [numbers intValue];
NSLog(@"Picked number %d ", numbers); // not %@ ..%@ is for objects .. not int
Run Code Online (Sandbox Code Playgroud)
NSString *intString = [NSString stringWithFormat:@"%d", myInt];
Run Code Online (Sandbox Code Playgroud)
http://forums.macrumors.com/showthread.php?t=448594