由于需要,现在我希望能让工程中出现的所有TableView都执行某一个代理方法,比如说:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
但是由于controller数量巨大,又分散在工程里的很多文件夹中,如果可以的话我不太想一个个找出来单独添加...
请问有什么比较方便快捷的全局添加的方法?
高洛峰2017-04-17 17:31:02
A better way would be to let all your UITableViewControllers inherit a common parent class, and then write this method in the parent class. If this method is also used in subclasses, call super first.
Another way is to take a look at Method Swizzling. It can perfectly solve your needs without changing the previous code one by one. But be careful not to abuse this black technology, and don’t use it if you can, because it will be confusing if used too much.
黄舟2017-04-17 17:31:02
Inherit a UITableViewController, and write proxy methods in the parent class
大家讲道理2017-04-17 17:31:02
First create a UITableView of the parent class, and everything else inherits from this parent class