NSNotificationCenter的简单应用
来源:互联网 发布:mac see sheer试色 编辑:程序博客网 时间:2024/05/06 02:13
在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应用总结
- std::queue
- Ubuntu下手动安装flashplayer(自动安装失败)
- java如何创建并初始化一个动态的二维数组
- cocos2d-X之CCUserDefault
- Ubuntu12.04用户以root身份登录
- NSNotificationCenter的简单应用
- ACRush 楼天成回忆录
- MBProgressHUD开源loading状态
- java final
- nanoScroll demo
- 关于加班
- 电容触摸屏
- JavaScript 创建对象
- cin和cout的重要知识