swift UITabelVIew - 纯代码自定义tabelViewCell
2015-12-08 14:57
429 查看
//
// CustomTableViewCell.swift
// tab
//
// Created by su on 15/12/7.
// Copyright © 2015年 tian. All rights reserved.
//
import UIKit
class CustomTableViewCell: UITableViewCell {
var nameLabe: UILabel!
var typeLabel: UILabel!
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.seupUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func seupUI() {
nameLabe = UILabel(frame: CGRect(x: 10, y: 10, width: 20, height: 20))
nameLabe.backgroundColor = Tools().RGB(r: 122, g: 111, b: 123)
self.addSubview(nameLabe)
typeLabel = UILabel(frame: CGRect(x: 10, y: 40, width: 20, height: 20))
typeLabel.backgroundColor = UIColor.blackColor()
self.addSubview(typeLabel)
}
// func initWith(restName: String, restLocation: String){
// nameLabe.text = restName
// typeLabel.text = restLocation
//
// }
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
// override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
// super.init(style: UITableViewCellStyle, reuseIdentifier: String?)
// }
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
//
// ThreeViewController.swift
// tab
//
// Created by su on 15/12/7.
// Copyright © 2015年 tian. All rights reserved.
//
import UIKit
class ThreeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.grayColor()
self.navigationItem.title = "cc"
let right = UIBarButtonItem(title: "alertView", style: UIBarButtonItemStyle.Plain, target: self, action: "go:")
self.navigationItem.rightBarButtonItem = right
tableView = UITableView(frame: self.view.bounds)
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(CustomTableViewCell.self, forCellReuseIdentifier: "cell")
self.view.addSubview(tableView)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let identifier = "cell"
var cell = tableView.dequeueReusableCellWithIdentifier(identifier, forIndexPath: indexPath) as? CustomTableViewCell
if cell == nil {
cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: identifier)
}
cell?.nameLabe.text = "123434555677yhgfcdxs"
cell?.typeLabel.text = "gggggggggggggggggggg"
return cell!
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80
}
func go(right:UIBarButtonItem){
let pushVC = PushViewController()
self.navigationController?.pushViewController(pushVC, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
// CustomTableViewCell.swift
// tab
//
// Created by su on 15/12/7.
// Copyright © 2015年 tian. All rights reserved.
//
import UIKit
class CustomTableViewCell: UITableViewCell {
var nameLabe: UILabel!
var typeLabel: UILabel!
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.seupUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func seupUI() {
nameLabe = UILabel(frame: CGRect(x: 10, y: 10, width: 20, height: 20))
nameLabe.backgroundColor = Tools().RGB(r: 122, g: 111, b: 123)
self.addSubview(nameLabe)
typeLabel = UILabel(frame: CGRect(x: 10, y: 40, width: 20, height: 20))
typeLabel.backgroundColor = UIColor.blackColor()
self.addSubview(typeLabel)
}
// func initWith(restName: String, restLocation: String){
// nameLabe.text = restName
// typeLabel.text = restLocation
//
// }
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
// override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
// super.init(style: UITableViewCellStyle, reuseIdentifier: String?)
// }
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
//
// ThreeViewController.swift
// tab
//
// Created by su on 15/12/7.
// Copyright © 2015年 tian. All rights reserved.
//
import UIKit
class ThreeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.grayColor()
self.navigationItem.title = "cc"
let right = UIBarButtonItem(title: "alertView", style: UIBarButtonItemStyle.Plain, target: self, action: "go:")
self.navigationItem.rightBarButtonItem = right
tableView = UITableView(frame: self.view.bounds)
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(CustomTableViewCell.self, forCellReuseIdentifier: "cell")
self.view.addSubview(tableView)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let identifier = "cell"
var cell = tableView.dequeueReusableCellWithIdentifier(identifier, forIndexPath: indexPath) as? CustomTableViewCell
if cell == nil {
cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: identifier)
}
cell?.nameLabe.text = "123434555677yhgfcdxs"
cell?.typeLabel.text = "gggggggggggggggggggg"
return cell!
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80
}
func go(right:UIBarButtonItem){
let pushVC = PushViewController()
self.navigationController?.pushViewController(pushVC, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
相关文章推荐
- swift编码出现Call can throw, but it is not marked with 'try' and the error is not handled错误的解决
- Swift学习之路 -- 枚举和结构体
- 【菜鸟初学Swift】IOS平台常用传感器的使用方式
- Swift!代码实现UI基础控件
- Swift----单列的正确编写方式
- swift 学习之 UIAlertViewController
- 如何使用Instruments诊断App(Swift版):起步
- swift - 动态计算文本高度
- swift学习之UITabelView ----使用xib定义cell
- swift学习之UITabelView ----UITableViewCell
- swift学习之-- UIAlertVIewController - uiactionsheet
- swift学习之-- UIAlertViewController -alert
- Swift中的元组(turple)
- Swift 开源那点事
- Swift中的闭包
- Swift -- 泛型
- Swift -- protocol、extension
- Swift学习——Swift解释具体的基础(六)
- 程序猿必知的swift单例编写的正确方式
- ios9中新建swift工程并采用OC混编的方式,keywindow=nil的解决办法