• 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



  • 相关阅读:
    mysql启动和关闭外键约束的方法(FOREIGN_KEY_CHECKS)
    如果感觉不好,最后一面你需要更努力表达你的优势。最后一面打动面试官的可能往往是你的真诚和热情
    你的最终目的不是要进入该公司,而是要进入该公司你最想去的部门乃至项目组
    如果你说最近在看《诛仙》,平时喜欢玩LOL,你就是在把自己往悬崖上推
    Qt中嵌入Directx11(有句柄就可以)
    2015腾讯暑期实习武汉站面试经历(大学里的小朋友有这样的技术水平,只能说他规划的好、觉醒的早)
    NET Core开发-获取所有注入(DI)服务
    jQuery.data的是jQuery的数据缓存系统
    理解数字图像处理中的卷积
    Obstack是C标准库里面对内存管理的GNU扩展
  • 原文地址:https://www.cnblogs.com/yuhaojishuboke/p/5155878.html
Copyright © 2020-2023  润新知