Ios Swift-UITableView在UIViewController中,不调用UITableView函数

Ios Swift-UITableView在UIViewController中,不调用UITableView函数,ios,uitableview,swift,Ios,Uitableview,Swift,我在UIViewController中插入了一个tableview。但是我的代码不起作用。当我检查时,我发现没有一个tableview函数没有被调用 class CustomViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var authorArticlesTableView: UITableView! var a

我在UIViewController中插入了一个tableview。但是我的代码不起作用。当我检查时,我发现没有一个tableview函数没有被调用

    class CustomViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

        @IBOutlet weak var authorArticlesTableView: UITableView!

        var authorid: Int!
        var authorname: String!
        var articles: [JSON]? = []

        func loadArticles(){
            let url = "http:here.com/" + String(authorid) + "/"
            println(url)
            Alamofire.request(.GET, url).responseJSON { (Request, response, json, error) -> Void in
                if (json != nil){
                    var jsonObj = JSON(json!)
                    if let data = jsonObj["articles"].arrayValue as [JSON]?{
                        self.articles = data
                        self.authorArticlesTableView.reloadData()
                    }
                }
            }
        }
        override func viewDidLoad() {
            super.viewDidLoad()
            self.loadArticles()
            println("viewDidLoad")
        }

         func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
             println("numberOfRowsInSection")
            return self.articles?.count ?? 0
        }

         func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as! CustomTableViewCell
            cell.articles = self.articles?[indexPath.row]
            println("cellForRowAtIndexPath")
            return cell
        }


         func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
            performSegueWithIdentifier("WebSegue", sender: indexPath) 
            tableView.deselectRowAtIndexPath(indexPath, animated: true)
        }
有什么解决办法吗


谢谢,

设置表
委托
数据源

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.delegate = self
    tableView.dataSource = self
}

必须将视图控制器设置为表视图委托/数据源:

添加到
viewDidLoad
的末尾:

authorArticlesTableView.delegate = self
authorArticlesTableView.dataSource = self

有时,如果您忘记将UITableViewCell拖放到UITableView。XCode不理解TableView有单元格。 默认情况下,将UITableView拖放到UIViewController中时。我看到UITableView有一个手机。但您也需要将UITableViewCell拖放到UITableView中


这是我的工作。

在你的工作环境中这样做是有意义的

 @IBOutlet weak var authorArticlesTableView: UITableView!
因此,它将成为

 @IBOutlet weak var authorArticlesTableView: UITableView! {
        didSet {
            authorArticlesTableView.delegate = self;
            authorArticlesTableView.dataSource = self;
        }
    }

是否设置了代理和数据源?