簡體   English   中英

iOS:“在創建字典時嘗試從對象[1]中插入nil對象”

[英]iOS: “attempt to insert nil object from objects[1]” when creating dictionary

我正在創建一個自定義導航欄類​​並使用以下代碼自定義它的標題屬性:

self.titleTextAttributes = @{ UITextAttributeFont: bariol,
                              UITextAttributeTextColor: [UIColor whiteColor]
                            };

但是,當我運行代碼時,它返回以下錯誤消息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]'

我正在使用Xcode 4.6並在使用iOS 6的設備上運行。

聽起來你的bariol對象是nil 你不能將nil存儲在字典中。

編輯:

實際上,你確定這是正確的代碼行嗎? 您的錯誤引用了NSPlaceholderArray ,這表明它是@[]字面值的問題,而不是@{}字面值。

文字的參數(字典的值和鍵)不能nil

如果您更喜歡不太嚴格的構造函數,可以考慮使用+[NSDictionary dictionaryWithObjectsAndKeys:]

這個錯誤似乎在其他地方。 它指向對象'1'處的數組錯誤。 在你的情況下你有一個字典和對象'1'是UITextAttributeTextColor: [UIColor whiteColor]永遠不會是零。

暫無
暫無

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

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