使用预构建的 UITabBarController 将数据发送到另一个视图?
我使用 Xcode 创建了一个选项卡栏应用程序作为两个视图。
第二个视图是 UITableViewController。
我正在努力做的是当按下第二个选项卡时将数据发送到该视图。我已将选项卡栏委托给我的 AppDelegate 类并实现了此功能:
-(void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController
{
// Override point for customization after application launch.
statisticsViewController* assignmentListcont = [statisticsViewController alloc];
NSManagedObjectContext* context = [self managedObjectContext];
assignmentListcont.managedObjectContext = context;
[assignmentListcont release];
}
第二个视图显示正常,但数据尚未传递。我想这是因为我还没有编写第二个视图转换,但如果我已经有一个 .xib 文件为我做这件事,我不确定如何做到这一点?有没有什么方法可以毫无问题地传递数据,甚至在视图内部检索数据?
I have created a Tab Bar Application using Xcode that as two views.
The secound view is a UITableViewController.
What I am struggling to do is send data to this view, when the second tab is pressed. I have delegated the Tab Bar to my AppDelegate class and implemented this function:
-(void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController
{
// Override point for customization after application launch.
statisticsViewController* assignmentListcont = [statisticsViewController alloc];
NSManagedObjectContext* context = [self managedObjectContext];
assignmentListcont.managedObjectContext = context;
[assignmentListcont release];
}
The second view is displaying fine but the data hasn't been passed. I imagine its because I haven't programmed the second views transition but I'm unsure of how to do this if I already have a .xib file doing it for me? Is there some way to just pass the data without problems or even retrieve the data once inside the view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用通知。
在您想要接收数据的视图中,将其放入
viewDidLoad
中:然后实现接收该数据的方法:
现在,在数据源自的类中,您发布一条通知,通知新数据被创建。此外,您还可以传递希望其他方法接收的数据。
You could use notifications.
In the view that you want to receive the data, put this in
viewDidLoad
:Then implement the method that receives that data:
Now in the class where the data is originated from, you post a notification that new data was created. Also, you pass along the data that you want to have the other method receive.
我这样做是为了将值从一个视图控制器发送到另一个视图控制器,希望它有帮助
I've done this to send a value from one view controller to another, hope it helps