我已经浏览了该网站一段时间,我看到了一些东西,但对我没有任何帮助。不过这里是极端新手。
我正在尝试制作一个 2 组件选择器,从数组填充,从字典填充,从 plist 填充。组件填充,我有一个旋转一个组件的按钮。第二个按钮用于检查答案(第一个组件具有它们尝试与第二个组件中的大写字母匹配的状态),但这是它总是崩溃的地方。
我得到的错误如下:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[NSPlaceholderString initWithFormat:locale:arguments:]: nil argument”
* First throw call stack: (0x14b3022 0xeb3cd6 0x145ba48 0x145b9b9 0x916169 0x916ab4 0x3036 0x14b4e99 0x1914e 0x190e6 0xbfade 0xbffa7 0xbf266 0x3e3c0 0x3e5e6 0x24dc4 0x18634 0x139def5 0x1487195 0x13ebff2 0x13ea8da 0x13e9d84 0x13e9c9b 0x139c7d8 0x139c88a 0x16626 0x27ad 0x2715) terminate called throwing an exception(lldb)
我不确定我哪里出错了。我已经用硬编码数组完成了这个,它工作得很好。按钮的代码是这样的(请忽略开关代码,我还没有弄清楚如何使它工作,我希望屏幕变绿表示正确答案,红色表示不正确,但我更担心应用程序崩溃!):
-(IBAction)checkAnswer;{ NSInteger StateRow = [pickerCapital selectedRowInComponent:karrayStateComponent]; NSInteger CapitalRow =[pickerCapital selectedRowInComponent:karrayCapitalComponent];
NSString *state = [arrayState objectAtIndex:StateRow];
NSString *capital = [arrayCapital objectAtIndex:CapitalRow];
NSLog (@"%i",[pickerCapital selectedRowInComponent:karrayCapitalComponent]);
NSLog(@"%i", [pickerCapital selectedRowInComponent:karrayStateComponent]);
NSString *Title = [[NSString alloc]initWithFormat:@"You have selected %@ as the capital of %@.", capital, state];
NSString *Message =[[NSString alloc]initWithFormat:lblMsg];
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:Title message:Message delegate:@"" cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
if (StateRow == CapitalRow) {
lblMsg = @"You are correct!";
UIColor *myColor;
switch ([not sure what to use here]) {
case 0:
myColor = [UIColor greenColor];
break;
default:
break;
}
}
else {
lblMsg = @"Incorrect";
UIColor *myColor;
switch ([not sure what to use here]) {
case 0:
myColor = [UIColor redColor];
break;
default:
break;
}
}
}
如果有人可以为此提供任何帮助,我将不胜感激!谢谢!