import UIKit
class exploreViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var exploreTableView: UITableView!
var CELLHEIGHT = 200
var SECTIONHEADER = "SECTIONHEADER"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
exploreTableView.delegate = self
exploreTableView.dataSource = self
exploreTableView.register(UINib(nibName: "answerCell", bundle: nil), forCellReuseIdentifier: "cell1")
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return SECTIONHEADER
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.exploreTableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! answerCell
cell.name.text = "222222"
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return CGFloat(CELLHEIGHT)
}
}
我的numberOfSectionsInTableView
从来没有被调用,我不能得到两个部分。
发布于 2016-11-03 21:50:57
从您的代码来看,我相信您正在使用Swift3。然后,下面是UITableView在Swift3中的委托和数据源方法
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Configure the cell...
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
如您所见,numberOfSections函数的语法是wrong.That。
发布于 2020-03-15 03:28:49
这实际上是由于访问级别的解析。当我们自己不指定" public“时,编译器将其解析为某个私有实现的函数,甚至警告它与一个公共函数几乎匹配。如果忽略了这一点,那么它就忽略了这个函数,而是调用默认实现。希望这能帮上忙。
发布于 2016-11-04 04:15:08
func numberOfSectionsInTableView(tableView: UITableView) -> Int {返回1}
https://stackoverflow.com/questions/40415223
复制