我有一个Tabbar控制器,在该控制器中,我将显示5个以上的viewcontroller。一切都按预期进行。
但是现在我有一个具有UiTableView的ViewController,在单元格上单击“我想打开一个DetailView Controller”。
该DetailViewController将在Navigation View Controller中具有标题,并使用backbutton再次返回到列表。
请帮助我如何使用Swift进行操作?
答案 0 :(得分:2)
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func moveToNexScreen(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextVc = storyboard.instantiateViewController(withIdentifier: "NextViewController") as! NextViewController
let navigationVc = UINavigationController(rootViewController: nextVc)
present(navigationVc, animated: false, completion: nil)
}
}
class NextViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(self.closeBackButtonPressed))
}
@objc func closeBackButtonPressed(){
self.dismiss(animated: false, completion: nil)
}
}
将您的detailView放在UINavigationController(rootViewController: detailVc)
内,然后您可以显示它并具有后退按钮,可以以编程方式在detailsView上添加一个条形按钮项
答案 1 :(得分:1)
您要显示detailVC的vc应该嵌入在navigationController内,然后使用push / pop来管理show / hide
[[4 0 3 1 2]
[3 0 4 2 1]
[4 3 1 2 0]]
答案 2 :(得分:0)
使用-
#import <DetailViewController.h>
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSIndexPath *indexPath = [_tableView indexPathForCell:sender];
DetailViewController *details = (DetailViewController *)segue.destinationViewController;
details.dictionary = _json[indexPath.row]; // to pass data
}
在情节提要中-
Select Cell and drag a segue to Details view controller
答案 3 :(得分:0)