iPhone sdk在视图控制器之间传递消息

iPhone sdk在视图控制器之间传递消息,iphone,uiviewcontroller,Iphone,Uiviewcontroller,我想知道iPhone开发中应用程序流程的最佳实践是什么。 如何在ViewController之间传递消息? 你用单身吗?在视图之间传递它,或者您是否有一个用于管理流的应用程序的主控制器 谢谢。这门课有点重,但符合你描述的用法。其工作方式是,您的各种NSViewControllers向NSNotificationCenter注册,以接收他们感兴趣的事件 Cocoa Touch处理路由,包括为您提供类似“默认通知中心”的单例。有关更多信息,请参见苹果的。我使用的,这对于此类工作来说是非常棒的。可以将

我想知道iPhone开发中应用程序流程的最佳实践是什么。
如何在ViewController之间传递消息? 你用单身吗?在视图之间传递它,或者您是否有一个用于管理流的应用程序的主控制器

谢谢。

这门课有点重,但符合你描述的用法。其工作方式是,您的各种
NSViewController
s向
NSNotificationCenter
注册,以接收他们感兴趣的事件

Cocoa Touch处理路由,包括为您提供类似“默认通知中心”的单例。有关更多信息,请参见苹果的。

我使用的,这对于此类工作来说是非常棒的。可以将其视为广播消息的一种简单方式

要接收消息的每个ViewController都会通知默认的NSNotificationCenter它要侦听您的消息,当您发送消息时,每个连接的侦听器中的委托都会运行。比如说,

ViewController.m ViewControllerB.m 将产生(根据最先注册的ViewController的顺序):

NSNotificationCenter *note = [NSNotificationCenter defaultCenter];
[note addObserver:self selector:@selector(eventDidFire:) name:@"ILikeTurtlesEvent" object:nil];

/* ... */

- (void) eventDidFire:(NSNotification *)note {
    id obj = [note object];
    NSLog(@"First one got %@", obj);
}
NSNotificationCenter *note = [NSNotificationCenter defaultCenter];
[note addObserver:self selector:@selector(awesomeSauce:) name:@"ILikeTurtlesEvent" object:nil];
[note postNotificationName:@"ILikeTurtlesEvent" object:@"StackOverflow"];

/* ... */

- (void) awesomeSauce:(NSNotification *)note {
    id obj = [note object];
    NSLog(@"Second one got %@", obj);
}
First one got StackOverflow
Second one got StackOverflow