微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

swift 创建tableView 并实现协议


import UIKit class ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{ override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor=UIColor.orangeColor() var myTableView = UITableView(frame: CGRectMake(0,UIScreen .mainScreen().bounds.size.width,UIScreen.mainScreen().bounds.size.height),style: UITableViewStyle.Plain) self.view.addSubview(myTableView) myTableView.delegate = self myTableView.dataSource = self myTableView.backgroundColor = UIColor.whiteColor() } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int { return 10 } func tableView(tableView: UITableView,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return 60 } func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell = UITableViewCell() cell.textLabel?.text = "MyFirstSwift" cell.detailTextLabel?.text = "gaga" if indexPath.row%2 == 0{ cell.imageView?.image = UIImage(named: "image1") }else{ cell.imageView?.image = UIImage(named: "image2") } return cell } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐