zoukankan      html  css  js  c++  java
  • Swift

    import UIKit
    class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
        
        var ctrlnames:[String]?
        var tableView:UITableView?
      
    
        override func viewDidLoad() {
            super.viewDidLoad()
            
            self.ctrlnames = ["UILabel","UITextField","UIButton","UISwitch","UISegmentControl","UIImageView","UIProgressView","UISlider","UIAlertView"]
            
            self.tableView = UITableView(frame:self.view.frame, style: .plain)
            self.tableView?.delegate = self
            self.tableView?.dataSource = self
            
            self.tableView?.register(UITableViewCell.self, forCellReuseIdentifier: "cellID")
            self.view.addSubview(self.tableView!)
            
            //创建表头标签
            let frame = CGRect(x: 0, y: 0,  self.view.bounds.size.width, height: 30)
            let headerLabel = UILabel(frame: frame)
            headerLabel.backgroundColor = UIColor.black
            headerLabel.textColor = UIColor.white
            headerLabel.numberOfLines = 0
            headerLabel.lineBreakMode = .byWordWrapping
            headerLabel.text = "常见的 UIKit 控件"
            headerLabel.font = UIFont.italicSystemFont(ofSize: 20)
            self.tableView?.tableHeaderView = headerLabel
        }
        
        //表格行数
        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return self.ctrlnames!.count
        }
        
        //单元显示内容
        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let identyfy:String = "cellID"
            let cell = tableView.dequeueReusableCell(withIdentifier: identyfy, for: indexPath)
            cell.accessoryType = .disclosureIndicator
            cell.textLabel?.text = self.ctrlnames![indexPath.row]
            return cell
        }
        
        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            self.tableView?.deselectRow(at: indexPath, animated: true)
            
            let itemString = self.ctrlnames![indexPath.row]
            
            let alertController = UIAlertController(title: "提示", message: "你选中了(itemString)", preferredStyle: .alert)
            
            let okAction = UIAlertAction(title: "确定", style: .default, handler: nil)
            
            alertController.addAction(okAction)
            
            self.present(alertController, animated:true, completion: nil)
            
        }
        //滑动删除必须实现的方法
        func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
            let index = indexPath.row
            self.ctrlnames?.remove(at: index)
            self.tableView?.deleteRows(at: [indexPath], with: .bottom)
        }
        
        //滑动删除
        func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
            return .delete
        }
        //修改删除按钮的文字
        func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
            return "删除"
        }
        
    }
    
  • 相关阅读:
    Linux下VFP NEON浮点编译
    硬浮点 VFP
    程序员如何避免猝死?
    程序员谨防加班猝死之十大建议
    linux系统调用和库函数调用的区别
    彻底抛弃脚本录制,LR脚本之使用web_custom_request函数自定义
    LoadRunner监控mysql利器-SiteScope(转)
    linux mysql 数据库开启外部访问设置指南
    Java Web自定义MVC框架详解 (转)
    Jenkins+Ant+Jmeter搭建持续集成的接口测试平台(转)
  • 原文地址:https://www.cnblogs.com/baidaye/p/9323724.html
Copyright © 2011-2022 走看看