1.代理
委托者.h文件
@protocol DBDoorHoneListTabCollectionCellDelegate <NSObject>
- (void)selectedItemButton:(NSInteger)index;
@end
@interface DBDoorHoneListTabCollectionCell : UITableViewCell
@property(nonatomic,weak)id<DBDoorHoneListTabCollectionCellDelegate> DBDoorHoneListTabCollectionCellDelegate;
@end
委托者.m文件
if(self.DBDoorHoneListTabCollectionCellDelegate&&[self.DBDoorHoneListTabCollectionCellDelegate respondsToSelector:@selector(selectedItemButton:)]) {
[self.DBDoorHoneListTabCollectionCellDelegate selectedItemButton:indexPath.row];
}
代理控制器.m
listColCell.DBDoorHoneListTabCollectionCellDelegate = self;
- (void)selectedItemButton:(NSInteger)index
{
doorRow = index;
}
2.block
声明.h
typedef void (^ReturnTextBlock)(NSString *showText);//给block重命名,方便调用
@interface B : UIViewController
@property (nonatomic, copy) ReturnTextBlock returnTextBlock;//声明一个block属性
- (void)returnText:(ReturnTextBlock)block;//加上后方便第A视图书写该block方法
声明.m
- (void)returnText:(ReturnTextBlock)block {
self.returnTextBlock = block;
}
if (self.returnTextBlock != nil) {
self.returnTextBlock(self.inputTF.text);
}
调用.m
[bVC returnText:^(NSString *showText) {
self.showLabel.text = showText;
}];
3.通知中心
[[NSNotificationCenter defaultCenter]postNotificationName:@"currentItemIndex" object:@(index)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentItemIndex:) name:@"currentItemIndex" object:nil];
-(void )currentItemIndex:(NSNotification*)not{
NSInteger deviceId = [not.object integerValue];
}