1.block A页面 -> B页面(A push B页面,B页面传值给A)
A页面:
__block typeof(self) __weak weakSelf = self;
b.clickBlock = ^(NSString *str) {
NSLog(@"%@", str);
};
B页面:
h文件
typedef void(^xxxBlock)(NSString *str);
@property (nonatomic, copy)xxxBlock clickBlock;
m文件
if (self.clickBlock) {
self.clickBlock(data);
}
block直接作为参数写法:
- (void) xxx:(void(^)(NSString*))xxBlock;
2.deleget A页面 -> B页面(A push B页面,B页面传值给A)
A页面:
B * b = [[B alloc] init];
b.delegate = self;
#pragma mark - xxxDelegate
- (void) sendMuArrayClickStr:(NSMutableArray*)arrayClickStr {
for (NSString *str in arrayClickStr) {
NSLog(@"-%@",str);
}
}
B页面:
h文件
@protocol xxxTDelegate <NSObject>
- (void) sendMuArrayClickStr:(NSMutableArray*)arrayClickStr;
@end
@property (nonatomic, weak)id<xxxTDelegate> delegate;
m文件
if ([self.delegate respondsToSelector:@selector(sendMuArrayClickStr:)]) {
[self.delegate sendMuArrayClickStr:data];
}
3.notification A页面发送通知 B页面接收
A页面:
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICTION_TEST object:@"data"];
B页面:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationTest:) name:NOTIFICTION_TEST object:nil];
- (void)notificationTest:(NSNotification *)notification {
NSLog(@"注册通知测试成功--%@",notification.object);
}
- (void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}