自定义cell和控制器controller之间常用传值方式:
1.代理
(1)自定义cell.h中遵循协议,例如:

(2)声明代理属性:

(3)在cell.m中实现删除按钮的代理方法:

(4)在控制器中遵守该协议并实现方法:


2.block传值
(1)声明block:

(2)cell.m中实现block方法:

(3)controller.m中实现:

3.通知
(1)在cell.h中发布通知

(2)controller中实现监听通知

注意:移除通知中是移除当前控制器下所有的通知。也可也这样写:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSNotification_Name" object:nil];
表示移除当前控制器下通知名为“NSNotification_Name”的通知。
网友评论