2015-01-11 117 views
0

我使用didDeselectRowAtIndexPath通过不同的故事板像浏览:Segue公司VS didDeselectRowAtIndexPath

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    let story = ["News","Video","Twitter","Request Info","More"] 

    let vc = self.storyboard?.instantiateViewControllerWithIdentifier(story[indexPath.row]) as NewsFeedTableViewController 
    self.presentViewController(vc, animated: true, completion: nil) 

} 

然而,Navigation Bar显示不出来,当我使用此功能。但是,当我使用segue时,出现Navigation Bar

现在的问题是:

  1. tableViewCells不能Segue公司超过1分镜
  2. 需要导航栏在App滚动(这似乎需要Segue

任何通过此解决方案?

回答

2

你正在使用presentViewController,这就是为什么你没有得到NavigationBar,它以模态方式呈现视图。取而代之的是pushViewController像:

self.navigationController?.pushViewController(vc, animated: true) 

可能在你的故事板的SEGUE类型将是push,这就是为什么你所得到的导航栏。

你可能会喜欢下面:

  1. presentViewController:animated:completion:
  2. ViewController Programming Guide for iOS
+0

我无法将普通的'ViewController'导入它,因为它只能推送作为基本视图控制器的'TableViewController'。斯威夫特说“Swift Dynamic Caste Failed”。任何解决方案? – tika

+0

@ user2078462:不,这是不正确的,你可以推动任何viewcontrollers(如果你的父视图中有一个UINavigationCotroller) –

+0

看起来像加载推送新的ViewController的父级的'super.viewDidLoad()' – tika

0

您呈现下一个视图控制器,并没有把它。 (至少在1情况下)所以你有一个模式链接,没有导航控制器!

您可以使用.pushViewController或只需performSegue并确保您的segue类型为push。我会去performSegue并更改每个switchcase中的identifier名称。

而且你还可以通过在prepareForSegue

-1

数据好叫performSegue在didSelectRow。并在perpareSegue方法中执行操作。

+0

这样做有什么问题? – coreDeviOS