资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Swfit学习tableview-创新互联

class OnrViewController:UIViewController,UITableViewDelegate,UITableViewDataSource{

专注于为中小企业提供成都网站设计、成都网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业蠡县免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了近1000家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

  //创建tableview

  var  tableView : UITableView?

  let URL :String = "http://piao.163.com/m/movie/list.html?type=0&city=110000&apiVer=14&mobileType=android&deviceId=r4a5ba63afbabd7a70ceeaf8485f7942e&channel=wandoujia&ver=4.9"

  //创建一个数组

  var dataSource:NSArray = NSArray()

 

  override func viewDidLoad() {

      super.viewDidLoad()

      // Do any additional setup after loading the view.

   

  }

 

  override func viewDidAppear(animated: Bool) {

      super.viewDidAppear(animated)

      //创建UI

      creatUI()

      //创建 数据源

      createDataSource()

  }

 

  func creatUI() {

      tableView = UITableView(frame: self.view.bounds,style: .Plain)

      tableView!.delegate = self

      tableView!.dataSource = self

      tableView!.separatorStyle = .SingleLineEtched

     

      self.view.addSubview(tableView!)

  }

 

  func createDataSource (){

      let url:NSURL = NSURL(string: URL)!

      let request : NSURLRequest = NSURLRequest(URL:url)

      NSURLConnection.sendAsynchronousRequest(request, queue:NSOperationQueue.mainQueue()) { (response, data, error) in

          let json :AnyObject =try!NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments)

          self.dataSource = json.objectForKey("list") as!NSArray

          self.tableView!.reloadData()

      }

     

  }

 

  //代理方法

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

      return self.dataSource.count;

  }

 

  //代理方法 获取cell

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell {

      let identifer = "tableviewcell"

      var cell = tableView.dequeueReusableCellWithIdentifier(identifer)

      if (cell == nil) {

          cell = UITableViewCell(style:.Default,reuseIdentifier: identifer)

          cell!.selectionStyle = .None

      }

//        cell!.text Label!.text = "tableviewcell"

      let obj:NSDictionary = self.dataSource[indexPath.row] as!NSDictionary

      let name:String = obj.objectForKey("name")as!String

     

      cell!.textLabel!.text = name

      cell!.backgroundColor = UIColor.blueColor()

      return cell!

  }

 

  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath) {

      if (indexPath.row == 0) {

          print("sdadadadad")

      }

  }

 

  func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath:NSIndexPath) -> CGFloat {

      return 200

  }

附件:http://down.51cto.com/data/2367835

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


网站名称:Swfit学习tableview-创新互联
标题URL:http://cdkjz.cn/article/eoddh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220