搜索tableview行单击以进入详细信息视图

时间:2016-08-08 06:20:36

标签: ios objective-c uitableview uisearchcontroller

我在HomeController中实现了UISearchController。通过这种方式

SearchTableViewController *searchResults = (SearchTableViewController *)self.controller.searchResultsController;
[self addObserver:searchResults forKeyPath:@"myResult" options:NSKeyValueObservingOptionNew context:nil];
searchResults.rootHomeController=_homeController;
[self presentViewController:self.controller animated:YES completion:nil];

我的搜索值在SearchTableViewController中显示得很好。现在我需要在SearchTableViewController UITableView单元格点击后通过这种方式尝试但不能正常工作。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
                                @"Main" bundle:[NSBundle mainBundle]];
AlbumSongListController *detailSongList=[storyboard instantiateViewControllerWithIdentifier:@"AlbumSongListControllerID"];
    [self presentViewController:detailSongList animated:YES completion:nil];

我需要传递导航控制器,以便我可以返回搜索控制器

3 个答案:

答案 0 :(得分:0)

通过声明类似:

之类的变量将结果传递给另一个视图控制器
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
                    let resultViewController = storyBoard.instantiateViewControllerWithIdentifier("DestViewController") as!  DestViewController
                    resultViewController.result = self.result
                    self.presentViewController(resultViewController, animated:true, completion:nil)

答案 1 :(得分:0)

plz在app delegate中使用此代码

 -(BOOL) application: (UIApplication * ) application didFinishLaunchingWithOptions: (NSDictionary * ) launchOptions {
    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:
        @ "Main"
        bundle: [NSBundle mainBundle]
    ];

    HomeVcController * HomeVcControllerOb = [storyboard instantiateViewControllerWithIdentifier: @ "HomeVcControllerID"];

    UINavigationController * navController = [
        [UINavigationController alloc] initWithRootViewController: HomeVcControllerOb
    ];
    self.window.rootViewController = navController;

}
homeVWcontroller上的

和隐藏的NavigationBar

[self.navigationController setNavigationBarHidden:YES animated:YES];

然后才使用这个

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:
    @ "Main"
    bundle: [NSBundle mainBundle]
];

AlbumSongListController * detailSongList = [storyboard instantiateViewControllerWithIdentifier: @ "AlbumSongListControllerID"];

[self presentViewController: detailSongList animated: YES completion: nil];

并在AlbumSongListController中显示导航栏

[self.navigationController setNavigationBarHidden:No animated:YES];

答案 2 :(得分:0)

您需要在HomeController中以root身份呈现带有SearchTableViewController的导航控制器。因此,您可以执行导航。

即。单击SearchTableViewController中的表格单元格(didSelectRowAtIndexPath委托),使用[self.navigationcontroller pushviewcontroller]推送详细视图控制器,您将通过这样做返回到SearchTableViewController的导航。