在 Swift 中使用 UITableView 以编程方式切换视图
Programmatically switching views using UITableView in Swift
我无法使用 UITableView 切换到另一个视图控制器。我的代码如下。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let dashViewController = storyBoard.instantiateViewControllerWithIdentifier("menuView") as DashViewController
self.presentViewController(dashViewController, animated:true, completion:nil)
}
我点击了其中一个单元格,但它什么也没做。
我已经找到答案了,我忘了放UITableViewDelegate
。
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
}
并为视图控制器分配表视图
我无法使用 UITableView 切换到另一个视图控制器。我的代码如下。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let dashViewController = storyBoard.instantiateViewControllerWithIdentifier("menuView") as DashViewController
self.presentViewController(dashViewController, animated:true, completion:nil)
}
我点击了其中一个单元格,但它什么也没做。
我已经找到答案了,我忘了放UITableViewDelegate
。
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
}
并为视图控制器分配表视图