在swift中多次调用UItableView委托

在swift中多次调用UItableView委托,uitableview,delegates,swift2,Uitableview,Delegates,Swift2,这是我的自定义UITableViewController,我添加了任何其他代码,委托方法被调用了五次 import UIKit class SettingsViewController: UITableViewController { override func numberOfSectionsInTableView(tableView: UITableView) -> Int { print("numberOfSectionsInTableView calle

这是我的自定义UITableViewController,我添加了任何其他代码,委托方法被调用了五次

import UIKit

class SettingsViewController: UITableViewController {

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        print("numberOfSectionsInTableView called")
        return 2
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        print("numberOfRowsInSection called for section => \(section)")
        return 2
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: nil)

        cell.textLabel?.text = "hey"
        return cell
    }

}
日志:

调用NumberOfSectionsTableView 调用NumberOfSectionsTableView 为节调用的numberOfRowsInSection=>0 调用NumberOfSectionsTableView 为节调用的numberOfRowsInSection=>0 调用NumberOfSectionsTableView 为节调用的numberOfRowsInSection=>0 调用NumberOfSectionsTableView 为节调用的numberOfRowsInSection=>0 调用NumberOfSectionsTableView 为节调用的numberOfRowsInSection=>0

编辑

这是我从appDelegate启动的唯一类:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    window = UIWindow(frame: UIScreen.mainScreen().bounds)
    if let window = window {

        let nav = UINavigationController()
        nav.viewControllers = [Test()]
        window.rootViewController = nav
        window.makeKeyAndVisible()
    }
    return true
}

表视图数据源方法可能会被多次调用。无法保证它被调用的次数。由于实现了
UITableView
,在许多情况下,某些委托/数据源方法会被调用两次或多次,因为表视图必须刷新某些内容。这包括重新加载表视图、更改表头视图等情况。因此,您可能需要检查此类情况下的实现

在代码中的某个点上,调用重载数据amy I出错了吗?或者UItableviewcontroller被实例化两次。或者您的代理设置在错误的对象上是的,可能是,但这令人难以置信:我对所有内容都进行了双重检查,我的viewdidload只调用了一次,并且在该控制器中没有其他内容。TW您应该使用故事板否,我在故事板上遇到的问题比没有故事板时多。我知道这很糟糕,我大部分的项目都是在没有故事板的情况下完成的,但这是一件好事,特别是如果其他人以后不得不为你的项目工作的话。