[英]How to go from table view controller to a detail controller and go back
我有一個帶有單元格的表格視圖控制器,單擊單元格后我想打開一個用於顯示詳細信息的視圖控制器。 在詳細視圖控制器上,我想要一個導航操作,例如帶有項的導航欄,以返回到表視圖控制器。 然后,表視圖控制器應顯示我選擇的最后顯示的單元格,而不是第一個單元格。 我希望你明白我的意思。 而且我不想在顯示的表視圖控制器上有導航欄。 因此,導航控制器可能不是我的解決方案。
目前,我用於打開詳細視圖控制器的表視圖控制器的代碼如下所示:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vcMissionDetail : ViewControllerMissionDetail = self.storyboard?.instantiateViewControllerWithIdentifier("MissionDetail") as ViewControllerMissionDetail;
self.presentViewController(vcMissionDetail, animated: true, completion: nil)
}
我使用presentViewController
加載詳細視圖控制器。 使用prepareForSegue
是更好的解決方案嗎?
細節視圖控制器看起來像這樣。 我使用帶有條形按鈕項的導航欄返回到表視圖控制器(動作goToFeed
),但是我對這種解決方案不滿意。 我也想打開表視圖控制器:
import UIKit
class ViewControllerMissionDetail: UIViewController {
@IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func goToFeed(sender: AnyObject) {
//init view controller for feed
let vcFeed: UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewControllerFeed") as UIViewController;
//vcFeed.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
self.presentViewController(vcFeed, animated: true, completion: nil)
}
}
謝謝!
這是您可以做的回到表視圖控制器。 如果您已使用“推”進入詳細視圖控制器,請執行此操作,
@IBAction func goToFeed(sender: AnyObject) {
navigationController?.popViewController(...)
}
如果您使用“模式”來打開局部視圖控制器,請使用,
@IBAction func goToFeed(sender: AnyObject) {
self.dismissViewController(...)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.