我在选择一行时尝试推送新视图。
let identifiers:[String] = ["vc1", "vc2", "vc3", "vc4", "vc5"]
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let identifier = identifiers[indexPath.row]
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("\(identifier)") as! UINavigationController
self.presentViewController(vc, animated: true, completion: nil)
}
使用此tableView调用的所有不同视图都有自己的类和Storyboard ID。
目前我收到错误:
无法转换类型' testApp.CalculatorViewController'的值到' UINavigationController'
答案 0 :(得分:0)
我认为您正在尝试将UIViewController转换为UINavigationController。
请试试这个。这可能会对你有帮助。
let identifiers:[String] = ["vc1", "vc2", "vc3", "vc4", "vc5"]
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let identifier = identifiers[indexPath.row]
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("\(identifier)") as! UIViewController
self.navigationController?.pushViewController(vc, animated: true, completion: nil)
}