2016-08-03 79 views
-1

当我运行代码时,我成功地将JSON数据馈送到我的应用程序中,以呈现此关联的UIView。我有一个tableView充分链接到这个文件,当我运行应用程序时,我看到了tableview本身。但是3个数据源函数中没有一个会自动调用 - 在打了2个小时后,'wtf'打印语句,will.not.print。为什么我的UITableViewDataSource函数不被调用?

我错过了什么?此代码是相同到我写的所有其他tableviewdatasource代码,这根本不会工作或呈现我提供的JSON数据

有没有人有想法或建议?谢谢!

import UIKit 

class ChooseUserViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 


@IBOutlet weak var tableView: UITableView! 


var users: [BackendlessUser] = [] 

override func viewDidLoad() { 
    super.viewDidLoad() 

    loadUsers() 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

//MARK: UITableViewDataSource 

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 1 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    print("wtf") 
    return users.count 

} 

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

    let cell = tableView.dequeueReusableCellWithIdentifier("chooseCell", forIndexPath: indexPath) 

    let user = users[indexPath.row] 
    print("wtf!") 

    cell.textLabel?.text = user.email 

    return cell 


} 
} 
+3

你是否已经将你的TableView内的StoryView作为Delegate&Datasource赋给ViewController? – derdida

+0

您是否设置了数据源? – GoodSp33d

+0

@derdida这是另一回事。 :P – ZeMoon

回答

-1

万一你就被遗忘了使用Ctrl+Drag你需要在你viewDidLoad指定你在下列方式dataSourcedelegate想设置你的故事板dataSourcedelegate

override func viewDidLoad() { 
    super.viewDidLoad() 

    tableView.delegate = self 
    tableView.dataSource = self 

    loadUsers() 
} 

我希望这可以帮助你。

-1

答案:我没有将委托和我的表格对象的数据源连接到视图控制器 - OOPS!我觉得很傻,但这显然是我的问题

0

你有与视图控制器在故事板(界面生成器)连接的数据源和委托tableview。

相关问题