Swift代码库之分页制作tableview加载数据按钮(含demo源码)
实现代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 1){
let cell = tableView.dequeueReusableCell(withIdentifier: "loadmorecell", for: indexPath)
//cell.textLabel?.text="请点击载入更多"
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "VisitWordCell", for: indexPath) as! WordCell
let oneWord = wordList[indexPath.row]
cell.wName.text=checkSub(mStr: oneWord.wNameStr, sStr: "<PUA>")
cell.wImage.image = imageDB?.readData(tupian: oneWord.wImageStr)
//cell.wPinYin.text = "拼音:"+oneWord.wPinYin
//cell.wBushou.text = "部首:"+oneWord.wBushou
//cell.wZBihua.text = "笔画:"+String(oneWord.wZBihua)
cell.wXuhao.text = "序号:"+String(oneWord.wXuhao)
return cell
}
全部代码
import Foundation
import UIKit
class VisitAllVC: UIViewController,UITableViewDataSource,UITableViewDelegate {
var wordDB:RFWordDB?
var wordList:[FRWord] = []
var imageDB:KFImageDB?
var pageDB:RFPages?
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
wordDB = MyManager.sharedInstance.wordDB
pageDB = RFPages()
pageDB?.initBySql(sql: "select * from mword", step:20)
if ((pageDB?.isHasNext())!){
wordList = (pageDB?.nextPage())!
}
else{
wordList = wordDB!.readDataByDic(searchDic:["康","熙","字","典","查","汉"])
}
imageDB = MyManager.sharedInstance.imageDB
self.navigationItem.title = "汉字查询"
}
//mark- tableview
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (indexPath.section == 0)
{
return 110
}
else{
return 70
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let oneWord = wordList[indexPath.row]
let dvc=WDetailVC(wordItem: oneWord)
self.navigationController?.pushViewController(dvc, animated: true)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0)
{
return wordList.count
}
else{
return 1
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 1){
let cell = tableView.dequeueReusableCell(withIdentifier: "loadmorecell", for: indexPath)
//cell.textLabel?.text="请点击载入更多"
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "VisitWordCell", for: indexPath) as! WordCell
let oneWord = wordList[indexPath.row]
cell.wName.text=checkSub(mStr: oneWord.wNameStr, sStr: "<PUA>")
cell.wImage.image = imageDB?.readData(tupian: oneWord.wImageStr)
//cell.wPinYin.text = "拼音:"+oneWord.wPinYin
//cell.wBushou.text = "部首:"+oneWord.wBushou
//cell.wZBihua.text = "笔画:"+String(oneWord.wZBihua)
cell.wXuhao.text = "序号:"+String(oneWord.wXuhao)
return cell
}
func checkSub(mStr : String,sStr : String) -> String {
if (mStr.contains(sStr))
{
return ""
}
else
{
return mStr
}
}
//makr
}
网友评论