tableView任务状态改变, 任务删除 ,unwind返回,segment选择

import  UIKit

class test7ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {


    var  test7List = [test6Task]()

    func  tableView(_tableView:UITableView, numberOfRowsInSection section:Int) ->Int{

        return  test7List.count

    }


    func  tableView(_tableView:UITableView, heightForRowAt indexPath:IndexPath) ->CGFloat{

        return120

    }


    func  tableView(_tableView:UITableView, cellForRowAt indexPath:IndexPath) ->UITableViewCell{

        let  reuseID ="test7"

        //务必填写模版nib名

        let  nib =UINib(nibName:"test5TableViewCell", bundle:nil)


        tableView.register(nib, forCellReuseIdentifier: reuseID)



        var  cell = tableView.dequeueReusableCell(withIdentifier: reuseID) as? test5TableViewCell


        if  cell ==  nil{

            cell =test5TableViewCell(style: .default, reuseIdentifier:nil)

        }


        cell?.label1.text=test7List[indexPath.row].content


        cell?.label2.text=test7List[indexPath.row].startTime


        cell?.test5imageView.image=UIImage(named:"Simplicity丶-1")

        //改变任务栏状态

        if  test7List[indexPath.row].isCompleted == true {

            cell?.accessoryType= .checkmark

        }else{

            cell?.accessoryType= .none

        }

        return  cell!

    }


    func  tableView(_tableView:UITableView, commit editingStyle:UITableViewCell.EditingStyle, forRowAt indexPath:IndexPath){


        test7List.remove(at: indexPath.row)


        tableView.reloadData()


    }


    func  tableView(_tableView:UITableView, didSelectRowAt indexPath:IndexPath){


        test7List[indexPath.row].isCompleted = !test7List[indexPath.row].isCompleted

        //本行刷新

        tableView.reloadRows(at: [indexPath], with: .none)


    }


    override  func  viewDidLoad() {

        super.viewDidLoad()

        initData()

    }


    func  initData(){

        test7List.append(test6Task(type: .book, content:"书", startTime:"2019-04-27", isCompleted:false))

        test7List.append(test6Task(type: .movie, content:"电影", startTime:"2019-04-28", isCompleted:true))

        test7List.append(test6Task(type: .tour, content:"旅行", startTime:"2019-04-29", isCompleted:false))

        test7List.append(test6Task(type: .work, content:"工作", startTime:"2019-04-30", isCompleted:true))

        test7List.append(test6Task(type: .movie, content:"电影2", startTime:"2019-04-31", isCompleted:false))

    }

    //unwind返回,写在返回目标界面

    @IBAction func unwind(for unwindSegue:UIStoryboardSegue){

    }


//segment选择改变时触发
@IBActionfunctest8Segment(_sender:UISegmentedControl) {

        switch sender.selectedSegmentIndex {

        case0:

            test8Label.text="读书任务"

            test8ImageView.image=UIImage(named:"微笑 (1)")

        case1:

            test8Label.text="播放任务"

            test8ImageView.image=UIImage(named:"性别")

        case2:

            test8Label.text="等待任务"

            test8ImageView.image=UIImage(named:"我的")

        case3:

            test8ImageView.image=UIImage(named:"搜索")

            test8Label.text="太阳任务"

        default:

            letdate =Date()

            letdateFormat =DateFormatter()

            dateFormat.dateFormat="yyyy-MM-dd"

            test8Label.text= dateFormat.string(from: date)


            //test8Label.text = "更多任务"

            test8ImageView.image=UIImage(named:"空调")

        }

    }

}


    }


}

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

推荐阅读更多精彩内容