Capturing self strongly in this block is likely to lead a retain cycle
Piero87 opened this issue · comments
Piero87 commented
Hello, i have this uitableview:
@property (weak, nonatomic) IBOutlet UITableView *tableView;
then in the viewDidLoad i do this:
[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
// Move interface objects accordingly
// Animation block is handled for you
CGRect tableViewFrame = _tableView.frame;
tableViewFrame.size.height = keyboardFrameInView.origin.y;
_tableView.frame = tableViewFrame;
}];
i doesn't use self, but i however have this warning:
"Capturing self strongly in this block is likely to lead a retain cycle"
so i found this "trick":
__weak typeof(self) weakSelf = self;
[self.view addKeyboardPanningWithActionHandler:^(CGRect keyboardFrameInView) {
// Move interface objects accordingly
// Animation block is handled for you
CGRect tableViewFrame = weakSelf.tableView.frame;
tableViewFrame.size.height = keyboardFrameInView.origin.y;
weakSelf.tableView.frame = tableViewFrame;
}];
and i receive no warning, and seems work, but i read in the example project that i have to use this:
[self.view removeKeyboardControl];
but where i have to insert it?
Daniel Amitay commented
[self.view removeKeyboardControl];
should generally go in your view controller's -dealloc
method.
Kyle Fuller commented
@Piero87 CGRect tableViewFrame = _tableView.frame;
is using an ivar, thus retaining self.