
//
// tableVIEwCell.swift
// 练习
// Created by 刘阜澎 on 15/9/8.
// copyright (c) 2015年 刘阜澎. All rights reserved.
//
import UIKit
protocol tableVIEwCellDelegate {
// protocoldeFinition goes here
func buttonAction(sender:UIbutton)
}
class tableVIEwCell: UItableVIEwCell {
var delegate:tableVIEwCellDelegate?;
var _button:UIbutton!;
overrIDe init(style: UItableVIEwCellStyle,reuseIDentifIEr: String?) {
super.init(style: style,reuseIDentifIEr: reuseIDentifIEr)
self.selectionStyle=UItableVIEwCellSelectionStyle.None
self.creatUI()
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func creatUI()
{
_button=UIbutton.buttonWithType(UIbuttonType.Custom) as! UIbutton
_button!.frame=CGRectMake(self.contentVIEw.bounds.wIDth-100,5,80,30)
_button!.addTarget(self,action: "buttonAction:",forControlEvents: UIControlEvents.touchUpInsIDe)
_button.setTitle("确定",forState: UIControlState.normal)
_button.setTitlecolor(UIcolor.orangecolor(),forState: UIControlState.normal)
self.contentVIEw .addSubvIEw(_button!)
}
func buttonAction(sender:UIbutton)
{
self.delegate!.buttonAction(sender)
}
overrIDe func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
overrIDe func setSelected(selected: Bool,animated: Bool) {
super.setSelected(selected,animated: animated)
// Configure the vIEw for the selected state
}
}
// VIEwController.swift
// Created by 刘阜澎 on 15/8/31.
/*
var 声明变量关键字
window 是变量名
UIWindow 变量类型
? 可选类型在这里理解为空(nil)即可
*/
//声明一个全局变量
关于swift 中变量和常量:
变量
var 声明变量关键字
var 声明没有类型,在变量的名字后面可以指定类型
如:
var i:Int = 3; // 声明一个int类型的变量,变量名字为 i变量的值为 3
常量:
let 常量声明关键字
let 声明没有类型,在变量的名字后面可以指定类型,常量的值是不可以改变的
let d:Double =3.1415926;
d=3.5 //错误写法,因为常量的值是不可以改变的
*/
函数:
swift 函数特点
(1)函数的参数中有标签(OC中的方法签名)
(2)函数的返回值在函数的尾部用指针符号(箭头)指向返回值类型
(3)函数声明关键字:func
*/
import UIKit
class VIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDataSource,tableVIEwCellDelegate {
//数据源
let lsitData = ["Allen","Luc","liLei","XiaoMing"];
var _tableVIEw:UItableVIEw?;
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
self.creatUI()
}
func creatUI()
{
let tableheaderVIEw:UIVIEw=UIVIEw(frame: CGRectMake(0,0,self.vIEw.frame.size.wIDth,100))
tableheaderVIEw.backgroundcolor=UIcolor.orangecolor()
_tableVIEw=UItableVIEw(frame:CGRectMake(0,20,300))
self.vIEw.addSubvIEw(_tableVIEw!)
_tableVIEw!.delegate=self
_tableVIEw!.dataSource=self
_tableVIEw?.tableFooterVIEw=UIVIEw()
_tableVIEw?.tableheaderVIEw=tableheaderVIEw
_tableVIEw?.rowHeight=60
}
//分组个数
func numberOfRowsInSection(section: Int) -> Int{
return 1;
}
//cell 个数
func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int {
print(lsitData.count);
return lsitData.count;
}
//创建tableVIEwCell
func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell{
let cellindenttifIEr:String = "CellindenttifIEr";
let cell:tableVIEwCell = tableVIEwCell(style: UItableVIEwCellStyle.SubTitle,reuseIDentifIEr: cellindenttifIEr);
cell.delegate=self
cell.textLabel?.text = lsitData[indexPath.row];
cell.textLabel?.textcolor=UIcolor.redcolor()
cell.textLabel?.Font=UIFont.boldSystemFontOfSize(13.0)
//圆角
cell.imageVIEw?.image = UIImage(named:"avatars.jpg")
cell.imageVIEw?.layer.masksToBounds = true
cell.imageVIEw?.layer.cornerRadius = 5
cell.imageVIEw?.layer.borderWIDth = 2
cell.imageVIEw?.backgroundcolor=UIcolor.orangecolor()
cell.imageVIEw?.layer.bordercolor = UIcolor.yellowcolor().CGcolor
cell.detailTextLabel?.text = "hlello"
return cell;
}
//tablVIEwCell 点击事件
func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) {
let nextVIEw:NextVIEwController=NextVIEwController()
self.presentVIEwController(nextVIEw,animated: true,completion: nil)
}
func buttonAction(sender:UIbutton)
{
println("1111111")
}
func a(string:Nsstring)->Nsstring
{
var str:Nsstring="string"
str="string\(string)"
return str
}
func initData()
{
let str:Nsstring=self.a("1")
println(str)
//初始化空字符串
var emptyString=String()
if emptyString.isEmpty
{
println("emptySring是空字符串")
}
var variableString="horse"
variableString+=" and carriage"
println(variableString)
// horse and carriage
for Character in "Dog!"
{
println(Character)
}
// D
// o
// g
// !
//
let unusualMenagerIE = "0123456"
println("unusualMenagerIE has \(count(unusualMenagerIE)) characters")
}
}
总结以上是内存溢出为你收集整理的swift tableViewCell自定义全部内容,希望文章能够帮你解决swift tableViewCell自定义所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)