2013-08-27 24 views
0

我使用這個方法來定義navigationItem rightBarButtonItems:應用程序崩潰時,試圖定義rightBarButtonItems

UIImageView * imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"YouTube-icon"]]; 
UIBarButtonItem *barIcon = [[UIBarButtonItem alloc]initWithCustomView:imageView]; 

if ([videoArr count] > 0) { 
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:barIcon,self.aToZButton, nil]; 
} else { 
    self.navigationItem.rightBarButtonItem = barIcon; 
} 

[imageView release]; 
[barIcon release]; 

而當調試是:

self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:barIcon,self.aToZButton, nil]; 

的應用程序崩潰與:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType isSystemItem]: unrecognized selector sent to instance 0x1e5eecd0' 

編輯

我注意到,只有當我使用rightBarButtonItem然後rightBarButtonItem時發生崩潰。 如果我只使用rightBarButtonItems它不會崩潰

+0

爲什麼要釋放兩次imageView? – Levi

+0

這是錯誤的,我編輯代碼 – MTA

+0

顯示你的代碼爲aToZButton以及 – NightFury

回答

1

似乎在某個地方你發佈對象太早(內存管理問題)。 NSCFType是iOS SDK中內部未公開的類,這裏顯示的事實意味着在完成該過程之前,您的類的內存空間已經釋放。