Question

I have the a crash problem-> ([AGIPCAssetsController numberOfSectionsInTableView:]: message sent to deallocated instance 0x1976d7b0) , and it sometimes happens, but sometimes doesn't happen. So, I have no idea how to solve it. It seems I did something wrong in tableview memory management. I tested in iOS7/iOS7.1 iphone4. I didn't test much about other version/phones. Here's my code.

@interface AGIPCAssetsController : UIViewController<UITableViewDataSource, 
UITableViewDelegate, AGIPCGridItemDelegate,UIAlertViewDelegate >{
}
@property (retain,nonatomic) IBOutlet UITableView *tableView;

I set tableview property to retain, but it call numberOfSectionsInTableView after dealloc. Here're my questions. 1. any idea to solve it? 2. any idea to workaround. such as call [NSThread sleepForTimeInterval:0.5]; in the beginning of dealloc , to keep object alive.

Was it helpful?

Solution

Just set tableView's delegate and dataSource to nil before viewcontroller will be deallocated. For example:

_tableView.delegate = nil;
_tableView.dataSource = nil;
[self.navigationController popViewControllerAnimated:YES];

And in most cases, you should use weak attribute for tableView instead of retain which equals to strong in ARC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top