【问题标题】:presentViewControler pushes all Controllers to stackpresentViewControler 将所有 Controller 推入堆栈
【发布时间】:2017-03-22 06:57:00
【问题描述】:

我有一个 tableView 作为我的第一个视图。每个单元格都是可点击的,点击时,我使用 presentViewController 来显示带有新数据的当前视图。我没有导航栏,所以我不能使用导航控制器和推送。问题是每次我点击一个单元格时,它都会显示一个新视图(这很好),但是在按下后退按钮时,它只会后退一步,但我想让它进入第一个视图。我该怎么做?

print("clicked " + String(indexPath.row) )
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("playVideo") as! PlayVideoViewController

preferences.setValue( self.video[indexPath.row].id , forKey: "id" )
//self.dismissViewControllerAnimated(false, completion: nil)
  self.presentViewController(vc, animated: true, completion: nil)

返回:

self.dismissViewControllerAnimated(true, completion: nil)

【问题讨论】:

  • 如果你使用 UINavigationController,你可以通过使用 -pushViewController:animated: 方法推送它在导航控制器堆栈中显示“vc”,返回按钮将调用 -popToRootViewControllerAnimated: 导航控制器方法。
  • @IgorBidiniuc 我没有navigationController,所以我不能用它
  • 那么为什么你不能使用它呢?你可以隐藏导航栏。
  • @IgorBidiniuc 谢谢,我不知道我可以隐藏导航栏。我想我可以使用它。

标签: ios swift uiviewcontroller presentviewcontroller


【解决方案1】:

如果您想回到第一个 VC,请使用该代码:

self.view.window!.rootViewController?.dismissViewControllerAnimated(true, completion: nil)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 2011-02-27
    • 2018-03-27
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多