ios - 如何将对象转至 UITabBarController

标签 ios objective-c uitableview uitabbarcontroller segue

我正在尝试将对象从表格单元格转换为 UITabBarController。我将 segue 发送到 View Controller 的代码是这样的:

#import "DetailViewController.h"

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"UpdateContacts"]) {
        NSManagedObject *selectedDevice = [self.contactarray objectAtIndex:[[self.tableView    indexPathForSelectedRow] row]];
        DetailViewController *destViewController = segue.destinationViewController;
        destViewController.contactdb = selectedDevice;
        refreshControl = nil;
    }
}

我还在 DetailsViewController.h 中添加了 contactdb 属性 这个工作正常,现在我不知道如何将它转换为 UITabBarController,所以我可以从我在 UITabBarController 中的 2 个 View Controller 访问它。

最佳答案

我不清楚,你说的DetailViewController是不是你的TabBarController?

一般来说,当你想在流程比正常情况复杂一点的 View Controller 之间传递数据时,你可以使用通知/监听器模式。例如,在传递 Controller 中你会做这样的事情:

[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_REFRESH 
                                                    object:contactDb];

在您的接收 Controller 中,您将像这样注册收听通知:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(gotData:) 
                                             name:NOTIFICATION_REFRESH 
                                           object:nil];

在同一个 Controller 中,这里是捕获通知和对象的代码:

- (void)gotData:(NSNotification *) notification {
   NSObject *myData = [notification object];
}

您需要像这样在 header 中定义通知类型:

extern NSString* const NOTIFICATION_REFRESH;

它在 .m 文件中的实现是这样的:

NSString* const NOTIFICATION_REFRESH = @"notificationRefresh";

关于ios - 如何将对象转至 UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21362948/

相关文章:

ios - 无法使用 iOS6.1 sdk 构建适用于 IOS 版本 1.7.0 的 Google Maps SDK

ios - 最后在 XCUI TestCase 期间停止在 UITableView 上滚动

iphone - 容器类的内存管理

ios - Objective-C : several categories on one class

objective-c - 如何在 tvOS 中设置 TableViewCell 焦点颜色

ios - 如何使今日提醒显示我需要的所有信息?

objective-c - MKMapView addAnnotation 未立即添加注释

ios - UITableViewAutomaticDimension 在 iOS 9 中无法正常工作

iphone - UITableView : detecting click on '-' button in edit mode

ios - 在 UITableView 中带导航的 UITableView