numberOfSectionsInTableView不起作用
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
从来没有被调用,我不能得到2节。
从你的代码中,我相信你正在使用Swift3。 然后,下面是Swift3中UITableView的委托和数据源方法
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函数的语法是错误的,这就是原因。
func numberOfSectionsInTableView(tableView:UITableView) – > Int {return 1}
- 雨燕:永无止境的彩虹
- Swift iAd – 超过10个ADBannerView警告实例和CGAffineTransformInvert:奇异matrix输出
- UIGraphicsBeginImageContext线程安全吗?
- NSURLConnection授权标头不工作
- iOS中具有通用数据模型的自定义可重用数据源。
- 如何获得UITableViewCell的圆angular边缘的方式,允许用户select单元格背景颜色? (但不使用GROUPED模式)
- iOS – 这是更好的select把图像? 核心graphics(PaintCode应用程序)与图像文件(PNG)
- 不能更改另一个类IOS的BOOL值
- CoreData问题: – :无法识别的select器发送到实例