2010-10-24 40 views
6
-(void)showsearch:(id)sender 
{ 
    SearchViewController *searchview =[[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil]; 

    settingpopoverController = [[[UIPopoverController alloc] 
            initWithContentViewController:searchview] autorelease];    
    [searchview release]; 
    [settingpopoverController presentPopoverFromBarButtonItem:sender 
            permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 


} 

Khi tôi nhấp vào nút, ứng dụng bị lỗi và tôi nhận được thông báo [UIPopoverController dealloc] reached while popover is still visible..khi cửa sổ bật lên vẫn hiển thị

+0

bạn dường như đang trộn * chế độ xem * và * bộ điều khiển *. là SearchViewController một bộ điều khiển, nhưng bạn gọi nó là một khung nhìn. – Ross

Trả lời

3

Vấn đề là bạn đang thiết

settingpopoverController = 

khi bạn có ý nghĩa để làm

self.settingpopoverController = 

mà autorelease sẽ là chính xác. Cách thứ hai sử dụng các accessors thuộc tính, cái đầu tiên chỉ sử dụng iVar.

+0

người truy cập? có thật không? –

+0

@Sanjit Saluja, trong Obj-c 2.0 và hơn thế nữa, cú pháp thứ hai - giả sử đó là thuộc tính "giữ lại" - sẽ gọi "giữ lại" trên 'UIPopoverController' mà OP gọi autorelease on. Nếu không, khi phương thức hiện tại kết thúc, 'UIPopoverController' được tự động phát hành, đạt đến số lượng giữ lại là 0 và được dealloc'ed. Hãy cho tôi biết nếu bạn nghĩ rằng tôi đang thiếu một cái gì đó. –

6

Có một số cuộc thảo luận tốt về chủ đề này ở đây:

Retain/release pattern for UIPopoverController, UIActionSheet, and modal view controllers?

UIPopoverController and memory management

Các ý chính của nó là bạn cần phải:

  • gán popover autoreleased của bạn đến một giữ lại thuộc tính
  • đặt thuộc tính thành 0 trong giao dịch của chế độ xem của bạn loc
  • cũng như đặt nó thành không trong popoverControllerDidDismissPopover.
Các vấn đề liên quan