美文网首页学Swift挣美金
Swift代码库之分页UI部分基础代码

Swift代码库之分页UI部分基础代码

作者: iCloudEnd | 来源:发表于2019-07-31 21:34 被阅读4次

    Swift代码库之分页UI部分基础代码

    实现分类

      1. 新建浏览全部swift,VisitAllVC
      1. 尝试完成tableview的基础显示

    代码

    import UIKit
    
    class VisitAllVC: UIViewController,UITableViewDataSource,UITableViewDelegate {
        
        var wordDB:RFWordDB?
        var wordList:[FRWord] = []
        var imageDB:KFImageDB?
         @IBOutlet weak var tableView: UITableView!
        override func viewDidLoad() {
            super.viewDidLoad()
           
            
            wordDB = MyManager.sharedInstance.wordDB
            wordList = wordDB!.readDataByDic(searchDic:["康","熙","字","典","查","汉"])
            imageDB = MyManager.sharedInstance.imageDB
            
            self.navigationItem.title = "汉字查询"
        }
        
        //mark- tableview
        func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return 110
        }
        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 {
            return wordList.count
        }
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            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
    }
    
    

    运行效果

    Jietu20190731-213321@2x.jpg

    往期精彩

    相关文章

      网友评论

        本文标题:Swift代码库之分页UI部分基础代码

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