iOS:如何推送到 DetailView

标签 ios objective-c iphone segue spotlight

我正在尝试使用聚光灯结果引导用户到我的应用程序中的相应部分。

MainView 有几个按钮,允许转到应用程序的不同区域,其中之一是电话目录,位于它自己的 SplitViewController 内。 MasterViewTableView 中包含用户列表,DetailView 包含项目详细信息。

目前,我的 AppDelegate.m 中有以下内容。

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
    if ([userActivity.activityType isEqualToString:CSSearchableItemActionType]) {

        // uid = an Id field unique for each record
        NSString *uid = userActivity.userInfo[CSSearchableItemActivityIdentifier];

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *navController = nil;
        navController = [storyboard instantiateViewControllerWithIdentifier:@"PhoneDirectory"];

        if (navController != nil) {
            [[[self window] rootViewController] presentViewController:navController animated:YES completion:nil];
        }
    }

    return YES;
}

这是我的结构,希望它能很好地说明它。

Navigation Controller
|
|-- Main View
    |-- About View
    |
    |-- SplitView Controller (StoryboardID: PhoneDirectory)
        |-- Master View Controller
        |-- Detail View Controller
    |--Another View

我想要的是向 DetailView 展示用户的信息。在显示 MasterViewDetailView 的设备上,我希望 MasterView 看起来就像点击了该行。

实现此目标的最佳方法是什么?如何将 uid 传递给 MasterView,然后模仿点击来模拟相应行上的触摸。

注意:我在 MasterView 中的数据设置为 Arrays字典,以防万一如何通过uid找到正确的用户。

如果您需要更多信息,请告诉我。

最佳答案

MasterViewController.h

-(void)selectRowWithID:(NSString*)uid;

内部 MasterViewController.m

-(void)selectRowWithID:(NSString*)uid
    {
        NSPredicate* predicate = nil;
        //Your logic to find the match from array;

    NSArray* matches = [dataSourceArray filteredArrayUsingPredicate:predicate];

    if([matches count] > 0)
    {
        NSDictionary* match = matches[0];

        NSIndexPath* targetIndexPath;
        // Your logic to find out the indexPath for this match


        // Ask the table to select the row programatically
        [self.tableView selectRowAtIndexPath:targetIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];

        // Manually forward the event for this, as if user touched the cell
        // SDK won't forward this method call for programmatic cell selections
        [self tableView:self.tableView didSelectRowAtIndexPath:targetIndexPath];
    }
    else
    {
        NSLog(@"'uid' not found in the master table dataSource");
    }
}

这对我的大部分项目都很有效。

关于iOS:如何推送到 DetailView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37781597/

相关文章:

ios - 如何在 iOS info.plist 文件中本地化字符串数组

iPhone 多点触控 - 一些触摸调度 touchesBegan : but not touchesMoved:

iphone - 如何在 iPhone sdk 中更改 Facebook 语言?

ios - 当用户在 iOS 上打开应用程序切换器时监听事件

ios - 使用 NSUndoManager 强制保存 NSManagedObject

iphone - 在 iOS Game Kit 中,是接收数据 :fromPeer:inSession:context part of a delegate protocol?

ios - 如何在 TableView Cell 上使用 iOSCharts (https ://github. com/danielgindi/Charts)?

iphone - 如何解决 iphone 应用程序中的无效转换说明符警告

iphone - 如何截取 3D 转换图像的屏幕截图(或图像合并)?

iOS Framework 仅在设备上运行时构建