2016-01-19 93 views
0

在我的应用程序中,用户可以提交类似于Instagram的新帖子。但是,如果他们决定不发帖,他们可以按UITabBarButton上的“取消”按钮,它将加载最新的帖子。如何以编程方式显示UITableViewController

我环顾四周寻找解决方案,但他们主要是UIViewController

showViewController Not Working

不过,我需要的是强行打开一个UITableViewController。我的代码如下,我知道它不起作用,因为它不符合预期的UIViewController

@IBAction func cancelBtn(sender: UIBarButtonItem) { 
    self.navigationController?.pushViewController(LatestPostViewController as UITableViewController, animated: true) 
} 

编辑:新增为了更好地说明目的的屏幕截图。因此,“取消”按钮嵌入在Camera选项卡内的导航控制器中。我需要打开Latest Post标签当用户按下“取消”按钮上UINavigationBar

道歉,我没有足够的声誉,直接显示图像。

Image

+0

你在哪里调用上面的代码?从嵌入在UINavigationController中的UIViewController?否则self.navigationController将等于零。在尝试推送它之前,您还需要实例化一个LatestPostViewController的实例。就像,让latestPostViewController = LatestPostViewController(); self.navigationController?.pushViewController(latestPostViewController,animated:true) – beyowulf

+0

是的,我从嵌入在UINavigationController中的UIViewController调用。启动应用程序后,它会在我的'初始视图控制器'中加载LatestPostViewController。是否安全再次实例化? – jo3birdtalk

+0

你只想回到那个标签?或者你想推一些东西?我提交了一个我认为你想要的答案,但现在我想你只是想知道如何更改选项卡。 – beyowulf

回答

0

检查,以确保您的取消按钮操作设置正确。在您想要转移到相应选项卡的操作中:

@IBAction func cancelBtn(sender: UIBarButtonItem) { 
    self.tabBarController?.selectedIndex = 0 
} 
相关问题