我正在尝试将选项卡栏一页上输入的内容转换到另一页...例如,选项卡栏标签的第1页-文本字段(插入内容)生成......标签栏的第2页....标签栏的第3页...无论插入的是什么
如果有可能发生这样的事情请告诉我...提前谢谢你!
发布于 2011-09-20 10:32:15
是的,这是可能的。事实上,有几种方法可以做你想做的事情。从你描述你想要做什么的方式来看,我建议你看看NSNotificationCenter。基本上,当您设置视图控制器时,第二个和第三个视图控制器可以注册以接收某种通知。当文本字段的内容发生变化时,第一个视图控制器将“发布”一个通知。第二个和第三个将接收通知,然后更新其内容。
编辑:
//register for a notification. Whenever the notification is sent, mySelector: is called on self (probably done whe thn second and third controller are loaded)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mySelector:) name:@"NotificationName" object:nil];
//send a notification (done when the first view controllers action is finished)
[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationName" object:obj];发布于 2011-09-20 11:03:25
另一种方法是将app委托作为帮助。在appdelegate中创建一个属性,例如userName。在你想要访问的视图中导入appdelegate类。使用其属性在一个视图中进行存储,并在另一个视图中进行检索。您可以访问appdelegate单例实例属性,如下所示
((yourAppDelegate*)[[UIApplication sharedApplication] delegate]).userName = @"Set Value";在另一个视图的viewWillAppear中:
self.greetingLabel.text = ((yourAppDelegate*)[[UIApplication sharedApplication] delegate]).testString;可能不是最优雅的解决方案,只是实现结果的另一种方式。
发布于 2011-09-20 11:05:28
如果我正确理解了您的问题,请检查此SO 问题的答案。
https://stackoverflow.com/questions/7479401
复制相似问题