import “RootViewController.h”
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// self.view.backgroundColor = [UIColor grayColor];//注册变名通知、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ChangeNameNotification:) name:KNotifation object:nil];
}
//通知传值方法
-(void)ChangeNameNotification:(NSNotification*)notification{
NSDictionary *nameDictionary = [notification userInfo];
self.nameLabel.text = [nameDictionary objectForKey:@”name”];
}
import “SecondViewController.h”
//通知传值、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
- (IBAction)notificationMethod:(id)sender {
if ([self notEmpty]) {
[[NSNotificationCenter defaultCenter] postNotificationName:KNotifation object:self userInfo:@{@”name”:self.nameTextField.text}];
[self dismissViewControllerAnimated:YES completion:nil];
}else{
[self showAlert];
}
}
**
利用通知跳转tab页面
**
import “AppDelegate.h”
//initNotifition
[[[NSNotificationCenter defaultCenter]
rac_addObserverForName:TurnShoppingCartNotification
object:nil] subscribeNext:^(id x) {
[self turnShoppingCart];
}
];
- (void) turnShoppingCart {
UINavigationController nav = (UINavigationController )self.tabbar.selectedViewController;
[nav.topViewController.navigationController popToRootViewControllerAnimated:NO];
[self bk_performBlock:^(id obj) {
self.tabbar.selectedIndex = 1;
} afterDelay:0.01];
}
需跳转界面
[[NSNotificationCenter defaultCenter] postNotificationName:TurnShoppingCartNotification object:nil];