zoukankan      html  css  js  c++  java
  • tableview 与 tableview cell

    1.tableview cell:


    import Foundation
    import UIKit

    class CjwtCell: UITableViewCell {
    @IBOutlet var lb_content:UILabel!    //定义lable
    var data: NSDictionary?       //定义data类型
    override func layoutSubviews() {
    self.lb_content.text = self.data!["question"] as? String       //获取值的函数
    }

    }

    2.tableview:

    import Foundation
    import UIKit

    class ChangjwtController: UIViewController   //继承
    ,UITableViewDataSource
    ,UITableViewDelegate{
    @IBOutlet var quxiao:UIButton!
    var dataSourse=NSMutableArray()     //有一个类型不区分name string?
    @IBOutlet var tableview:UITableView!

    override func viewDidLoad() {
    super.viewDidLoad()
    self.tableview.dataSource = self  //表示函数对这个控件起作用
    self.tableview.delegate = self  //表示函数对这个控件起作用
    let nib = UINib(nibName: "CjwtCell", bundle: nil)  //因为要用到其他xib 故先定义nib
    self.tableview.registerNib(nib, forCellReuseIdentifier: "CjwtCell")  //这里面的CjwtCell为table view cell控件名

    self.title="我的";
    downloadaData()
    }

    @IBAction func OnBackup(sender:AnyObject){
    self.dismissViewControllerAnimated(true, completion: {})
    }

    func downloadaData(){
    let url="http://59.78.93.208:9097/CJWT"

    HttpRequest.request(urlString:url){(data) -> Void in
    if data == nil{
    let alertView=UIAlertView()
    alertView.title="温馨提示"
    alertView.message="加载失败"
    alertView.addButtonWithTitle("确定")
    alertView.addButtonWithTitle("取消")
    alertView.show()
    }
    else{
    let itemArray = data

    for item:AnyObject in itemArray!{
    self.dataSourse.addObject(item)
    }
    self.tableview!.reloadData()

    }
    }
    }

    //UITableViewDataSource   //获取tableview组数
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {   //获取你个tableview cell里面元素个数
    return self.dataSourse.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("CjwtCell", forIndexPath: indexPath) as? CjwtCell

    if indexPath.row < self.dataSourse.count {  
    let dataDict = self.dataSourse[indexPath.row] as! NSDictionary
    cell?.data = dataDict
    }


    return cell!
    }


    }

  • 相关阅读:
    树莓派:2安装MySQL
    树莓派:1组装启动
    NLifeBill第六章月总额报表
    NLifeBill第五章修改页面
    NLifeBill第四章添加页面
    NLifeBill第三章Angularjs使用
    NLifeBill第二章日历显示
    NLifeBill第一章项目搭建
    『ORACLE』 SQL语句简单应用(二)(11g)
    『ORACLE』 SQL语句简单使用(一)(11g)
  • 原文地址:https://www.cnblogs.com/to-creat/p/5368796.html
Copyright © 2011-2022 走看看