iOS-UITableView学习笔记

tableview 的cell点击事件
不重复使用的cell需要单独定义并实现跳转二级界面

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        // 不加此句时,在二级界面点击返回时,此行会由选中状态慢慢变成非选中状态。
        // 加上此句,返回时直接就是非选中状态。
        tableView.deselectRow(at: indexPath as IndexPath, animated: true)
        var vc = accountDetailViewController()
        switch indexPath.row {
        case 1:
             vc = accountDetailViewController()
            break
        case 2:
            
            break
        case 3:
            
            break
    
        default:
            break
        }
         self.navigationController?.pushViewController(vc, animated: true)
    }

重复使用的cell点击事件直接传值跳转二级界面可返回

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath) as! homeTableViewCell
        let vc = homeInfoViewController()
        vc.view.backgroundColor = UIColor.white
        self.navigationController?.pushViewController(vc, animated: true)

手动隐藏导航条

 //隐藏导航条
      self.navigationController?.isNavigationBarHidden = true

设置tableview自定义cell 无论是storyboard还是xib文件中,一定要在对应的cell名称,才能实现跳转和对应cell的显示


2DF1869D-9E32-45BF-A554-E6A930D85849.png
7D2DDB3A-5387-42C3-8572-BCD82422D6A7.png
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: messageCellID) as! accountTableViewCell
        let setting = settings[indexPath.section] as! [accountInfo]
        cell.setting = setting[indexPath.row]
        return cell
    }
//空cell
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
        return cell

自定义的tableview注册的方式

//注册tableview
 tableview = UITableView.init(frame:CGRect.init(x: 0, y: 105, width: 375, height: 603),style:UITableViewStyle.plain)
//注册自定义xib文件的cell
        let lnib = UINib(nibName: String(describing: TableViewCell.self), bundle: nil)
        tableview.register(lnib, forCellReuseIdentifier: StarsCellID)
//注册storyboard的cell
 // self.tableView!.register(TableViewCell().classForCoder, forCellReuseIdentifier: StarsCellID)

tableview使用的时候需要绑定数据源

 self.tableView!.delegate = self
 self.tableView!.dataSource = self

这次使用的显示两个界面的方式是设置tableview的head

tableView.tableHeaderView = headerView
private lazy var headerView: ScrollView = {
       var headerView : ScrollView! = nil
        headerView = ScrollView.init(frame: .init(x: 0, y: 0, width: SCREENW, height: 250), ImagesArr: ["img01","img_01","img_01","img_01","img_01"])
        headerView.delegate = self
        self.view.addSubview(headerView)
        return headerView
    }()

刷新控件使用的是第三方库http://www.hangge.com/blog/cache/detail_1407.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,019评论 3 119
  • 1.ios高性能编程 (1).内层 最小的内层平均值和峰值(2).耗电量 高效的算法和数据结构(3).初始化时...
    欧辰_OSR阅读 29,656评论 8 265
  • 终将胳膊是拧不过大腿的,她妥协了!当然还有因为她心里对万花筒外的世界存在的一丝恐惧感; 刚刚出社会的她心还...
    A_dream_阅读 194评论 0 1
  • I resemble as a walking corpse, drifting like a dandelio...
    玲玲A阅读 704评论 0 1
  • 今天不知怎么想发点牢骚。 解高数题目头很大也不知道该落笔写一些什么。人的一天也是这样从早上起床不知为何而忙...
    哗啦啦的生活阅读 285评论 0 1