博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS UI 21 消息通知
阅读量:7240 次
发布时间:2019-06-29

本文共 4975 字,大约阅读时间需要 16 分钟。

//

//  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

转载于:https://www.cnblogs.com/yuhaojishuboke/p/5155878.html

你可能感兴趣的文章
交换机、集线器、路由器区别(转)
查看>>
UITextField,UITextView字数限制
查看>>
Spring 循环依赖
查看>>
sencha touch 在线实战培训 第一期 第二节
查看>>
Mirror--使用证书配置镜像模板
查看>>
ArcGIS 10 安装程序及破解文件
查看>>
C#中读写JSON风格的配置信息
查看>>
Spring-Context之一:一个简单的例子
查看>>
(转)S5PV210 三个Camera Interface/CAMIF/FIMC的区别
查看>>
struct和typedef struct
查看>>
9.5 在 C# 中使用 F# 库
查看>>
2016第6周六
查看>>
Windows 下 绿化 Oracle
查看>>
利用京东云擎架设免费Wordpress 博客(git方式)
查看>>
Linux开发环境搭建与使用——ubuntu更新设置
查看>>
POJ 3740 Dancing Links
查看>>
iOS开发--使用NSMutableAttributedString 实现富文本
查看>>
十一、jdk命令之Jstatd命令(Java Statistics Monitoring Daemon)
查看>>
iOS开发小技巧--TableView Group样式中控制每个section之间的距离
查看>>
18.OGNL与ValueStack(VS)-值栈入门
查看>>