我有一個非常簡單的ViewController包含以下內容:視圖 - 控制釋放導致崩潰或奇怪的現象
@interface ServingsView : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *labelTitle;
@property (retain, nonatomic) IBOutlet UILabel *labelContent;
@property (retain, nonatomic) IBOutlet UIButton *buttonSelect;
我沒有添加代碼到該控制器的M檔。現在
,我創建這個視圖控制器,並添加其視圖滾動視圖:
for (NSSubArray * Choice in currentItem.ItemsArray)
{
stView * ChoiceView=[[stView alloc]initWithNibName:@"stView" bundle:nil];
ChoiceView.view.tag=1515;
[mScrollView addSubview:ChoiceView.view];
ChoiceView.view.frame=CGRectMake(0, [self getMinimumHeight]+h*ChoiceView.view.frame.size.height , 320, ChoiceView.view.frame.size.height);
ChoiceView.labelTitle.text=Choice.ArrayName;
[ChoiceView.buttonSelect addTarget:self action:@selector(onSubservingItemClicked:) forControlEvents:UIControlEventTouchUpInside];
ChoiceView.buttonSelect.tag=h;
h++;
increaseHeight+=ChoiceView.view.frame.size.height;
// here is the problem:
[ChoiceView release];
}
現在,我沒有使用任何地方ChoiceView後記。接下來發生的事情是,即使沒有顯示按鈕,該視圖也沒有響應。當在其環境中使用視圖進行滾動時,我會得到不同類型的異常。有時它的CALayer異常,有時是stView異常。當我刪除發行版時,一切正常。
我甚至創建了一個測試項目,它沒有發生在那裏,所以我在這裏失去了一些東西。
TY爲您的迴應! 這是一個4.3應用程序,所以我不能使用該API。 另外,我從來沒有得到UIViewControllerHierarchyInconsistency因爲它提到有這個代碼工作的樣本項目,我沒有檢查它... 另外,我沒有看到任何其他的方式來子視圖添加到滾動視圖,因爲它們是動態創建,我不知道會有多少人。 – donald 2012-08-06 07:50:32
如果您回到4.3,您可能需要通過創建一個包含視圖所有者的子控制器數組來創建自己的等效容器控制器。另一種相當安全的方法是設計不需要控制器並直接加載它們的自定義視圖。 (注意:它**是**可能有不一致的層次結構,而不會觸發發生該特定錯誤的事件。) – 2012-08-06 12:02:43
好的,所以我創建了一個數組來保存子視圖控制器,現在我得到一致的將它們從數組中移除時出錯:[CALayer release]:發送到釋放實例的消息。那裏有一點進展.... – donald 2012-08-06 14:07:17