张运涛

c++

   :: 首页 :: 联系 :: 聚合  :: 管理

常用链接

留言簿(4)

搜索

  •  

最新评论

//通知为MVCController的第三种方式,也是最高级的方式,其类似与windows上的SendMessagePostMessage一样.使用如下:

1.将要监听的对象加入Notification center:(一般在 viewDidLoad中)

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(showHere:) name:@"update" object: nil];

//将对象自己加入通知信息中心,当收到@"update"通知时,将调用showHere:函数.



2.实现showHere函数:

-(void)showHere:(id)sender

{

  UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"HelloWorld" message:@"In MainViewController!"  delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];

[alert show];

[alert release];

}



3.在需要的地方发送通知:

[[ NSNotificationCenter defaultCenter] postNotificationName:@"update" object:nil];



4.从Notification Center中移除加入的对象:(一般在 viewDidUnload中)

[[NSNotificationCenter defaultCenter] removeObserver:self];

 

 


 

 

 

posted on 2010-07-31 14:25 张运涛 阅读(321) 评论(0)  编辑 收藏 引用 所属分类: iphone

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理