2011-06-04 84 views
0

在模態視圖中,我有一個在viewDidLoad中分配並初始化的UIPickerView。去哪裏dealloc pickerview?

它被釋放在dealloc與該視圖中使用的其他對象。

這是一個不正確的方式釋放我的選擇器?爲什麼在模態視圖被解散後需要訪問它,因爲錯誤信息似乎暗示着?

殭屍日誌錯誤是:

-[UIPickerView release]: message sent to deallocated instance 0x5a441 

相關代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    //navigation bar stuff here 

    mcPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 244, 320, 216)]; 
    mcPickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; 

    // setup the data source and delegate for this picker 
    mcPickerDataSource = [[MCPickerDataSource alloc] init]; 
    mcPickerView.dataSource = mcPickerDataSource; 
    mcPickerView.delegate = mcPickerDataSource; 

    mcPickerView.showsSelectionIndicator = YES; 
    [self.view addSubview:mcPickerView]; 
} 

- (void)dealloc 
{ 
    [mc dealloc]; 
    [mcPickerView dealloc]; 
    [mcPickerDataSource dealloc]; 
    [mcVal release]; 
    [super dealloc]; 
} 
+0

請顯示您的代碼viewDidLoad和dealloc – jaminguy 2011-06-04 16:14:57

+0

添加了相關的代碼 – Ayrad 2011-06-04 16:24:44

回答

1

在你的dealloc方法,您[mcPickerView dealloc]大概也dealloc'd mcPickerDataSource你因爲mcPickerView持有至mcPickerDataSource引用。改變你的dealloc方法來釋放一切,除了超級應該修復這個問題。

1

viewDidLoad中的任何alloc'd:應該在viewDidUnload中釋放而不是釋放dealloc。這是因爲viewDidLoad和viewDidUnload可能會在對象的整個生命週期中被調用多次。在對象的生命週期中,Dealloc只被調用一次。