我有兩個UIView子類,比如說「Class A」和「Class B」。類A在其初始化程序中,代碼爲[self addSubview:instanceOfClassB];
。而在B類的drawRect:
是代碼行[self addSubview:imageViewInstance];
。同樣在B類的drawRect:
中,我將值分配給該imageView實例的animationImages
,animationDuration
和animationRepeatCount
屬性。但是,我也在此UIImageView實例上調用startAnimating
,但它總是使應用程序崩潰。然後,我嘗試從乙級的上海華盈的drawRect:
是UIImageView的實例調用startAnimating
,A級。但是,它仍然與錯誤崩潰:在drawRect之後有沒有直接調用的方法?
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
而且具有「主題1:信號SIGABRT」上線消息代碼爲[imageView startAnimating];
。
我懷疑它在這裏崩潰,因爲B類的drawRect
正在類的drawRect
之後調用,所以,當我告訴圖像視圖啓動動畫崩潰,因爲圖像觀點尚未創建。 所以基本上我問的是在什麼方法可以告訴圖像視圖開始動畫沒有崩潰?
您可以添加異常斷點以查看代碼崩潰的位置:http://developer.apple.com/library/ios/#recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html – 2013-04-21 07:11:56
@weichsel - 我已經確定它在哪裏崩潰;問題是我無法找到一種替代方法來完成我上面描述的內容。 – pasawaya 2013-04-21 07:15:26
問題 - 爲什麼在drawRect中添加imageViewInstance?爲什麼不在init方法中? – 2013-04-21 07:21:03