【发布时间】:2011-10-16 03:01:24
【问题描述】:
好的,我遇到了以下常见问题
[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
}
这是 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;
}
我想我需要将我的 NSNumber 对象的 NSArray 类型转换为字符串。我该如何正确地使用该语句:
stringIndex = [self.hours objectAtIndex:row];
谢谢!
【问题讨论】:
-
注:你不应该在
viewDidLoad中释放tempHours。您不拥有它,因为您没有创建它。
标签: objective-c ios nsstring int