美文网首页学Swift挣美金
Swift代码库之tablebiew 分页完整版(含源码)

Swift代码库之tablebiew 分页完整版(含源码)

作者: iCloudEnd | 来源:发表于2019-08-01 10:05 被阅读6次

    源码

    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) {
             if (indexPath.section == 1){
                 self.perform(#selector(loadTable), with: nil, afterDelay: 0.5)
                return
            }
            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
        @objc func loadTable() {
            if ((self.pageDB?.isHasNext())!){
                let rowNum=self.wordList.count-1
                
                self.wordList=self.wordList+(self.pageDB?.nextPage())!
                self.tableView.reloadData()
                self.tableView.scrollToRow(at: [0,rowNum], at: .middle, animated: true)
            }
            //
        }
    }
    

    程序代码下载

    相关文章

      网友评论

        本文标题:Swift代码库之tablebiew 分页完整版(含源码)

        本文链接:https://www.haomeiwen.com/subject/gtofdctx.html