当我选择一行时,我试图推送一个新 View 。
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 调用的所有不同 View 都有自己的类和 Storyboard ID。
此时我得到错误:
Could not cast value of type 'testApp.CalculatorViewController' to 'UINavigationController'
最佳答案
我认为您正在尝试将 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)
}
关于ios - 为 UITableView 的每一行推送不同的 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34535512/