Xcode 在ios6中将数据从详细信息传递到主信息
我正在使用xcode制作应用程序,在视图之间传递数据时遇到问题。Xcode 在ios6中将数据从详细信息传递到主信息,xcode,ios6,master,detail,Xcode,Ios6,Master,Detail,我正在使用xcode制作应用程序,在视图之间传递数据时遇到问题。 我想在详细视图中设置日历的日期。然后,当我返回主视图时,我想查看所选日期中的事件,但我不知道如何处理。 你能帮我吗 这是两个类之间的通信方式 ViewController *dvController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]]; // ViewController is contr
我想在详细视图中设置日历的日期。然后,当我返回主视图时,我想查看所选日期中的事件,但我不知道如何处理。
你能帮我吗 这是两个类之间的通信方式
ViewController *dvController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
// ViewController is controler where you want to send date from particular controler we are making object of ViewController where you want to send data
dvController.selectedBirthdate = selectedbirthdate;
dvController.selectedName = selectedname;
//you are sending data in above two lines just imagine you are sending string
[self.navigationController pushViewController:dvController animated:YES];
//then pushviewcontroller and there you go
[dvController release];
就这么简单
两个类之间通信的另一种方式是,app delegate将您的app delegate对象化,然后将您想要的内容分配给app delegate的特定变量,然后您可以在项目中的任何位置使用该变量
像这样创建应用程序委托对象
YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
//and then access the variable by appDelegate.variable
如果您使用的是故事板,那么您可以像下面这样使用prepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:...]) {
MyViewController *controller = (MyViewController *)segue.destinationViewController;
controller.myProperty1 = ...;
controller.myProperty2 = ...;
}
}
基本上有两种最常见的方法: 1) 如果在项目中使用故事板,请使用“展开”segue。这里对该方法进行了完美的讨论: 2) 使用委托模式。当我开始学习授权时,我发现以下教程非常有用:
您可以使用appDelegate中定义的全局数组来访问。好的!谢谢,我试着做。好的,这是做这个的好方法!!谢谢!!!我也这么做,但我有一个从大师到细节的顺序,当我再从一个细节到大师,Crashy你不需要再做一次从细节到主要的检查文档导航如何工作阅读全文并尝试理解它,问题就解决了,然后不要使用NSUserDefault它只用于存储诸如用户偏好之类的小东西如果我的东西有用,那么别忘了投票并接受答案:)