當我創建一個自定義導航欄類和定製它的使用下面的代碼title屬性:的iOS:「試圖插入從對象無對象[1]」創建字典
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.
這並不是那麼嚴格,它只是認爲如果在預期關鍵時發現'nil',參數就會停止。值得注意的是,如果你傳遞一個'nil'對象,你會得到完全相同的異常。 – 2013-02-26 22:34:29
@KevinBallard廢話。從[[NSDictionary dictionaryWithObjectsAndKeys:@「a」,@「a」,nil,@「b」,nil];'?它停止閱讀第一個零對象參數。 – justin 2013-02-26 22:51:58
對不起,我說的對象,當我說的關鍵(倒裝方法)。它無法區分'nil'對象和sentinel'nil'。嘗試使用'nil'作爲鍵,看看我的意思:'[NSDictionary dictionaryWithObjectsAndKeys:@「anObj」,@「aKey」,@「anotherObj」,nil,nil]'。 – 2013-02-26 22:54:42