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

后端 未结 3 1185
花落未央
花落未央 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:28

    From Setting delegate to nil in dealloc:

    It's a defensive programming move. It's clearing out the reference to the delegate object incase something else in your object tries to access the delegate after you've told it that you're done with it. As part of your dealloc you might have a method or do something that triggers a KVO notification that makes a call to the delegate. So setting the delegate's reference to nil prevents that from happening. If it did happen you could end up with some oddball crashes that are fun to reproduce and fix.

提交回复
热议问题