In dealloc method set any delegate to nil is needed or not needed

后端 未结 3 1188
花落未央
花落未央 2020-12-22 03:42

I have created tableview in my view by programmatic like below

table = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, 320, 370) style:UITableViewCel         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-22 04:06

    If you are deallocating an object that acts as the delegate to other objects, you need to make sure that you have set their delegates to nil, before you call [super dealloc] (assuming the normal pattern that objects do not retain their delegates). This is because when [super dealloc] has returned, this object is no longer a valid object and the objects it is a delegate to effectively have dangling references, if they have not been set to nil.

    In this particular case, you would probably get away without doing it because your object's dealloc probably won't get called except when the UI is being dismantled and the table view no longer needs to use its delegate or data source, but don't bet on it.

提交回复
热议问题