runtime 能否对某个协议方法进行修改?

比如我想在每个tableview的协议方法tableView:numberOfRowsInSection:执行时,运行我制定的代码。

 Method tableViewNumberOfRowsInSection = class_getInstanceMethod(self, @selector(customTableView:numberOfRowsInSection:));
    
    Method customTableViewNumberOfRowsInSection = class_getInstanceMethod(self, @selector(tableView:numberOfRowsInSection:));
    method_exchangeImplementations(tableViewNumberOfRowsInSection, customTableViewNumberOfRowsInSection);

试着写方法交换。但是好像没啥作用。

有其他办法没?

阅读 3.1k
1 个回答
新手上路,请多包涵

同问啊~~~

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进