Ios 如何在不使用顺序的情况下显示ViewController
我想在从tableView进行搜索并点击单元格后显示collectionView 我创建了一个searchController,它也是一个tableViewController,并实现了updateSearchResultsForSearchController(),它运行良好并显示我想要的结果 由于storyboard没有searchController,我无法在searchController和collectionViewController之间创建分段。我尝试的是Ios 如何在不使用顺序的情况下显示ViewController,ios,swift,Ios,Swift,我想在从tableView进行搜索并点击单元格后显示collectionView 我创建了一个searchController,它也是一个tableViewController,并实现了updateSearchResultsForSearchController(),它运行良好并显示我想要的结果 由于storyboard没有searchController,我无法在searchController和collectionViewController之间创建分段。我尝试的是 //PostListId
//PostListId is the storyboard id of postList(collectionview here)
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// Choose the viewController I wanna display
let postList = storyboard?.instantiateViewControllerWithIdentifier("PostListId") as! PostListController
// Send data to collectionView
postList.key = 1
// PresentViewController
self.presentViewController(postList, animated: true, completion: nil)
}
但是,当我在搜索后点击单元格时,我在这里得到了一个错误,没有错误消息反馈,为什么?尝试以下操作:
let postCtrl = PostListController() //create instance of your controller
postCtrl.key = 1
let navigationController = UINavigationController(rootViewController: postCtrl) //create navigation controller if you want
pushViewController(navigationController, animated: true) //display
或者,如果您愿意,也可以将控制器显示为模态:
presentViewController(postCtrl, animated: true, completion: nil)
到目前为止,您的代码看起来还不错。确保设置了情节提要id:
如果需要,可以使用情节提要场景。只需适当地设置视图控制器自定义类型