我是一个Objective C和Xcode的菜鸟,我一次只学习一步。我在一个特定的问题上一直在困扰我很多天,并且很难找到解决方案。我正在制作一个UIPickerVIew应用程序,它使用字典来填充选择器。 arrayStates是进入左侧组件的状态,而arrayCities是处于状态键的状态的城市。城市进入正确的组成部分。我认为这个问题已经缩小到一段代码中了。当我去填充选择器的值时,它会崩溃。我可以注释掉这段代码,它会运行得很好(只有问号作为选择器中的文本)。我得到这个错误:UIPickerView NSInvalidArgumentException',原因:' - [__ NSCFString superview]:无法识别的选择器发送到实例
NSInvalidArgumentException', reason: '-[__NSCFString superview]: unrecognized selector sent to instance
这里是代码块从我的.m文件导致错误:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger)component reusingView:(UIView *)view {
if (component == 0) {
return [arrayStates objectAtIndex:row];
}
else {
UILabel *lblCity=[[UILabel alloc] initWithFrame:CGRectMake(5,0,220,50)];
lblCity.text= [arrayCities objectAtIndex:row];
lblCity.backgroundColor = [UIColor clearColor];
lblCity.font = [UIFont boldSystemFontOfSize:18];
return lblCity;
}
}
下面是我改变了我的代码,它运行伟大!感谢您的快速和准确的回应!
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component == 0)
{
return [arrayStates objectAtIndex:row];
}
else
{
return [arrayCities objectAtIndex:row];
}
}
真棒!你是对的钱。非常感谢!我发布了我的更新代码,它运行的很好! – hansoac 2013-03-08 21:20:54