iOS UI 21 消息通知



//

//  rootViewController.m

//  UI - 大结局 消息通知

//

//  Created by dllo on 15/12/10.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "rootViewController.h"

#import "SencondViewController.h"

@interface rootViewController ()


@end


@implementation rootViewController


-(void)dealloc

{

    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"天王盖地虎" object:nil];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"小鸡炖蘑菇" object:nil];

    [super dealloc];

}


- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    self.navigationItem.title = @"第一页";

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(rihthAct)];

    //注册消息,以及接收到消息后的处理方式和暗号

    //所有注册了同样暗号消息的界面都能收到广播通知

    

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction) name:@"天王盖地虎" object:nil];

    

    //带参数的消息通知

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationChickAction:) name:@"小鸡炖蘑菇" object:nil];

    

    // Do any additional setup after loading the view.

}

- (void)notificationChickAction:(id)sender

{

    UIColor *color = (UIColor *)[sender object];

    self.view.backgroundColor = color;

}

- (void)notificationAction

{

    self.view.backgroundColor = [UIColor greenColor];

}

- (void)rihthAct

{    

    SencondViewController *root = [[SencondViewController alloc]init];

    [self.navigationController pushViewController:root animated:YES];

   

    [root release];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end

//

//  ThirdViewController.m

//  UI - 大结局 消息通知

//

//  Created by dllo on 15/12/10.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "ThirdViewController.h"


@interface ThirdViewController ()


@end


@implementation ThirdViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    self.navigationItem.title = @"第三页";

    self.view.backgroundColor = [UIColor redColor];

    

    

    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake(100, 100, 100, 100);

    button.backgroundColor = [UIColor orangeColor];

    [button addTarget:self action:@selector(buttonAct) forControlEvents:UIControlEventTouchUpInside];

    [button setTitle:@"" forState:UIControlStateNormal];

    [self.view addSubview:button];

    

    // Do any additional setup after loading the view.

}

- (void)buttonAct

{

//    //发送消息通知

//    [[NSNotificationCenter defaultCenter] postNotificationName:@"天王盖地虎" object:nil];

    

    //发送带参数的消息通知

    [[NSNotificationCenter defaultCenter] postNotificationName:@"小鸡炖蘑菇" object:[UIColor magentaColor]];

    

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end


//

//  SencondViewController.m

//  UI - 大结局 消息通知

//

//  Created by dllo on 15/12/10.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "SencondViewController.h"

#import "ThirdViewController.h"

@interface SencondViewController ()


@end


@implementation SencondViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor redColor];

    self.navigationItem.title = @"第二页";

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(rihthAct)];

    

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction) name:@"天王盖地虎" object:nil];

    

    // Do any additional setup after loading the view.

}

- (void)notificationAction

{

    self.view.backgroundColor = [UIColor greenColor];

}


    // Do any additional setup after loading the view.


- (void)rihthAct

{

    ThirdViewController *root = [[ThirdViewController alloc]init];

    [self.navigationController pushViewController:root animated:YES];

    [root release];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end



posted @ 2015-12-13 16:39  挽月细数风流  阅读(137)  评论(0编辑  收藏  举报