如何通过UINavigationController从UITabBarController子ViewController执行Segue到具有UINavigationController的UITableViewController的DetailView?在多个控制器上执行segue
有两个孩子的,的firstView(最多查看符号)和NavigationController(联系人符号)一个TabBarController。
FirstView有一个按钮,它应该执行一个循环到Show Profile VC。 NavCont有一个TableView,子类为All ProfilesTVC,原型单元为子类。 AllProfilesTVC有一个由重用单元格显示的三个名称的数组。
哪一个viewcontroller我必须在FirstView(HomeVC)函数prepareForSegue中进行实例化和准备,以及在故事板中创建的segue直接指向哪里?所以我在“John's”DetailView。 当我向ShowProfileVC执行segue时,我可以将后退按钮返回到所有ProfilesTVC吗?
还有谁想要在github repo
的firstView/HomeVC.swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// what do we do here ???
}
AllItemsTVC
class AllItemsTVC: UITableViewController {
let profiles = ["Joe", "John", "Ken"]
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return profiles.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
let profile = profiles[indexPath.row] as String
cell.textLabel?.text = profile
return cell
}
@IBAction func cancelFromShowProfile(segue: UIStoryboardSegue) {
}
// MARK: - Navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
switch identifier {
case "ShowProfile":
if let showProfileVC = segue.destinationViewController as? ShowProfileVC {
// pass the data to the destinationVC
let selectedProfile = profiles[tableView.indexPathForSelectedRow()!.row] as String
showProfileVC.name = selectedProfile
}
default: break
}
}
}
尝试ShowProfileVC
class ShowProfileVC: UIViewController {
@IBOutlet weak var textLabel: UILabel! {
didSet {
textLabel.text = name
}
}
var name = "Label"
override func viewDidLoad() {
super.viewDidLoad()
}
01 GitHub库
}
感谢您的任何帮助。