func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
print("WTF is this getting hit...")
let Cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
Cell.textLabel?.text = self.funlists[indexPath.row]
print("This better be getting hit")
return Cell;
}
由于某种原因,这个方法没有被调用。
我已设置以下
uiTableView.delegate=self
uiTableView.dataSource=self
uiTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
我也包括了,
class viewUniversityList: UIViewController, UITableViewDelegate, UITableViewDataSource {
答案 0 :(得分:2)
这可能有几个原因。其中一些是:
如果您在ViewController文件中使用tableView,那么您应该添加UITableViewDelegate
和UITableViewDelegate
个委托,如下所示:
class ViewController: UIViewController,UITableViewDelegate, UITableViewDelegate { ... }
如果您在代码中创建了tableView
,那么您应该执行此操作
以下:
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
如果这一切都已完成,或者您已通过故事板创建UITableView
并使用单独的类UITableView
的子类,那么肯定需要定义该
以下方法:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {...}
〜func numberOfSectionsInTableView(tableView: UITableView) -> Int {...}
是可选的,但定义它是一个很好的做法。
答案 1 :(得分:1)
delegate
属性?
还应实施tableView
答案 2 :(得分:1)
您必须设置代理并声明您使用这些协议
在didLoad中的file.m中
_table.delegate = self;
_table.dataSource = self;
当你声明界面时,在file.h中你必须添加这些协议UITableViewDelegate
和UITableViewDataSource
Xcode将告诉您必须实施哪些方法来尊重协议。