簡體   English   中英

NSInvalidArgumentException,nil參數

[英]NSInvalidArgumentException, nil argument

我已經瀏覽了一段時間,但看到了幾樣東西,但對我來說卻無濟於事。 極端的新手在這里。

我試圖做一個2組件選擇器,從數組填充,從字典填充,從plist填充。 組件填充,並且我有一個旋轉一個組件的按鈕。 第二個按鈕用於檢查答案(第一個組件的狀態要與第二個組件中的大寫字母匹配),但這總是導致崩潰。

我得到的錯誤如下:

*由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'* -[NSPlaceholderString initWithFormat:locale:arguments:]:nil參數'

*第一擲調用堆棧:(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)終止叫做拋出異常(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;
    }
}

}

如果有人可以提供任何幫助,我將不勝感激! 謝謝!

檢查兩件事:

  • lblMsg在哪里聲明或分配了值?
  • 您確定對[arrayCapital objectAtIndex]的調用的資本和州不為零嗎?

具體來說: NSString文檔指出“重要提示:如果format為nil,則引發NSInvalidArgumentException。” 用於initWithFormat。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM