• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

swifttableViewController

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

tableViewController 控制器

import UIKit  
 
class ViewController: UITableViewController {  
      
    // 静态数据数组,存放模型  
    var arrs = [ZLPlace]()  
      
    override func viewDidLoad() {  
        super.viewDidLoad()  
          
        let place2 = ZLPlace()  
        place2.place = "zhang2"  
        arrs.append(place2)  
          
        let place3 = ZLPlace()  
        place3.place = "zhang3"  
        arrs.append(place3)  
          
        let place4 = ZLPlace()  
        place4.place = "zhang1"  
        arrs.append(place4)  
          
        self.tableView.reloadData()  
    }  
      
    // 数据源方法, 返回多少组  
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {  
        return 1;  
    }  
      
    // 每组有多少行  
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {  
        return arrs.count;  
    }  
      
    // 每行展示什么内容  
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {  
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell  
          
        let place = arrs[indexPath.row]  
          
        cell.textLabel.text = place.place  
          
        return cell;  
          
    }  
      
    // 点击每个cell触发什么事件  
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {  
          
        let place = arrs[indexPath.row]  
        place.visited = !place.visited;  
          
        let cell = tableView.cellForRowAtIndexPath(indexPath)  
        cell?.backgroundColor = UIColor.clearColor()  
        if(place.visited){  
            cell?.accessoryType = UITableViewCellAccessoryType.Checkmark  
        }else{  
            cell?.accessoryType = UITableViewCellAccessoryType.None  
        }  
    }  
      
    // 点击编辑按钮  
    @IBAction func editing(sender: AnyObject) {  
        self.tableView.setEditing(true, animated: true)  
    }  
      
    // 删除每个cell  
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {  
        if editingStyle == UITableViewCellEditingStyle.Delete{  
            arrs.removeAtIndex(indexPath.row)  
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)  
        }  
    }  
      


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
关于Swift中的Array.contains方法发布时间:2022-07-13
下一篇:
AswiftTour(2)ControlFlow发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap