Art*_*sev 27 int objective-c nsstring ios
好吧,我有以下常见问题
[NSCFNumber isEqualToString:]: unrecognized selector sent to instance
但这次我不确定如何解决它.
这是宣言中的 viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *tempHours = [NSMutableArray array];
for (int i = 0; i < 12; i++) {
[tempHours addObject:[NSNumber numberWithInt:(i+1)]];
}
self.hours = tempHours; // 'hours' is a synthesized NSArray property of the ViewController
[tempHours release];
// two more similar array declarations here
}
Run Code Online (Sandbox Code Playgroud)
这是UIPickerView的代码方法,其中东西中断(例如,if语句)
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *stringIndex = [NSString stringWithFormat:@"Row #%d", row];
if(component == 0) {
return stringIndex = [self.hours objectAtIndex:row];
}
// more code for other components (of the same form) here
return stringIndex;
}
Run Code Online (Sandbox Code Playgroud)
我想我需要NSArray的NSNumber对象被类型化为字符串.如何使用该声明正确执行此操作:
stringIndex = [self.hours objectAtIndex:row];
谢谢!
小智 45
return [NSString stringWithFormat:@"%@",[self.hours objectAtIndex:row]];
Run Code Online (Sandbox Code Playgroud)
你正在返回一个NSNumber所持有的东西self.hours.由于NSString是预期的返回值,你应该通过创建一个字符串:
[NSString stringWithFormat:@"%@", [self.hours objectAtIndex:row]];
Run Code Online (Sandbox Code Playgroud)
或重新评估你的意图.你真的想以这种方式存储索引,还是想存储NSStrings?
| 归档时间: |
|
| 查看次数: |
35198 次 |
| 最近记录: |