NSNotificationCenter的简单应用
来源:互联网 发布:玉米基因组数据库 编辑:程序博客网 时间:2024/05/19 06:46
在AppDelegate中添加UITabBarController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
tabBarController = [[UITabBarController alloc] init];
ChinaViewController* vc1 = [[ChinaViewController alloc] init];
HubeiViewController* vc2 = [[HubeiViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
ChinaViewController类中添加方法
-(id)init {
if ([super init] != nil) {
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"China" image:nil tag:1];
self.tabBarItem = item;
[item release];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test:)
name:@"wangsong" object:nil];
}
- (void)test:(NSNotification*)notify{
NSString *testString = @"Test Notification!";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Notification"
message:testString
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
在HubeiViewController类中添加方法:
-(id)init {
if ([super init] != nil) {
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Hubei" image:nil tag:1];
self.tabBarItem = item;
[item release];
}
return self;
}
添加一个button的响应方法:
- (IBAction)btPressed{
[[NSNotificationCenter defaultCenter] postNotificationName:@"wangsong" object:nil];
}
点击这个button的时候,将会调用ChinaViewController中的(void)test:(NSNotification*)notify方法,弹出alertShow。
- NSNotificationCenter的简单应用
- NSNotificationCenter的简单应用
- iOS-NSNotificationCenter的应用
- NSNotificationCenter 的简单使用
- NSNotificationCenter的简单使用总结
- ios NSNotificationCenter 的简单使用
- iOS NSNotificationCenter的简单使用
- 一个简单的NSNotificationCenter使用
- NSNotificationCenter 用法 一个简单的使用 NSNotificationCenter 的代码例子
- iOS中NSNotificationCenter的简单使用
- NSNotificationCenter defaultCenter 通知的简单实用
- 简单介绍下NSNotificationCenter
- 简单介绍下NSNotificationCenter
- 简单介绍NSNotificationCenter
- NSNotificationCenter简单使用
- iOS通知问题之:一眼就看懂的NSNotificationCenter应用
- iOS监听模式系列之NSNotificationCenter的简单使用
- 通知中心NSNotificationCenter应用总结
- Address already in use: JVM_Bind
- Yii Framework 开发教程(23) 数据库-概述
- ASP.NET保存信息总结(Application、Session、Cookie、ViewState和Cache等)
- 3D游戏引擎特效系统设计
- 网站安全检测工具
- NSNotificationCenter的简单应用
- 如何给 NPM 设置代理
- java 如何调用外部的 环境的程序
- iTunes注册
- 结构异常和C++异常
- ML:aPP:7.线性回归<Linear Regression>
- 什么是ROM、RAM、存储容量
- The Phantom of the Opera-7、My angel of music
- setPadding无效