代理声明:
//oc调用代理 @objc(NurseListCellDelegate) protocol NurseListCellDelegate : NSObjectProtocol{ func nurseListCellDidClickedDeleteNurseAction(nurseListCell: NurseListCell) func nurseListCellDidClickedFreezeNurseAction(nurseListCell: NurseListCell) } class NurseListCell: UITableViewCell{ weak var delegate : NurseListCellDelegate? }
代理触发
func delNurseAction() { if (delegate != nil && (delegate?.respondsToSelector(Selector("nurseListCellDidClickedDeleteNurseAction")))!) { delegate!.nurseListCellDidClickedDeleteNurseAction(self) } } func freezeNurseAction() { if (delegate != nil && (delegate?.respondsToSelector(Selector("nurseListCellDidClickedFreezeNurseAction")))!) { delegate!.nurseListCellDidClickedFreezeNurseAction(self) } }
代理使用
//在oc中创建后,直接添加代理 nurseCell.delegate = self; //实现 - (void)nurseListCellDidClickedDeleteNurseAction:(NurseListCell *)nurseListCell{ NSLog(@"%s",__func__); } - (void)nurseListCellDidClickedFreezeNurseAction:(NurseListCell *)nurseListCell{ NSLog(@"%s",__func__); }