zoukankan      html  css  js  c++  java
  • 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



  • 相关阅读:
    【请教】在vim中如何快速选中一个单词?并且让文本中的所有这个
    SQL中为了加强分类表的记录有效性,把主键和外键设计在了同一张表内
    JS不忘本之switch篇~建立一个菜单,并为菜单的参数来设置它的具体操作
    JS不忘本之JS类篇~类,方法,属性,子类,扩展方法在JS里的实现
    移入页面上空文本框时,让它变为焦点,移出清除焦点
    EF中数据优先,模型优先和代码优先
    关于ApplicationContext的初始化
    Linux下无线路由器的软件开发
    as3实现的拼图游戏
    AppWidgets
  • 原文地址:https://www.cnblogs.com/yuhaojishuboke/p/5155878.html
Copyright © 2011-2022 走看看