创建一个类继承自tableView.
在那个文件中这样写,然后使用这个方法创建出来的tableView就有属性了.
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style);
backgroundColor = UIColor.orangeColor();
// 隐藏垂直方向的滚动条
showsVerticalScrollIndicator = false;
delegate = self;
dataSource = self;
rowHeight = 150;
}
然后在单独创建一个继承自cell的类
// MARK:
// MARK: 加载xib
/// 类方法加载xib,从xib获取cell
class func familyCellLoadXib(tableView: UITableView) -> XNFamilyCell {
let identifier = "familyTabelViewCellIdentifier";
var cell = tableView.dequeueReusableCellWithIdentifier(identifier) as? XNFamilyCell ;
if cell == nil {
// 从xib 获取cell
cell = NSBundle.mainBundle().loadNibNamed("XNFamilyCell", owner: nil, options: nil).last as? XNFamilyCell;
}
return cell!;
}
想让cell显示对应内容
声明一个模型属性,重写didSet
/// 获取到的数据 数组转模型之后
var familyArray = XNFamilyArray() {
// 值被改变前调用
willSet{
}
// 值被改变后调用
didSet{
//print("didSet");
// 用户类型
userType.text = XNStirngUserType(familyArray.IDType);
// 昵称
userName.text = familyArray.OwnerName;
// 号码
userPhoneNumber.text = "电话: " + familyArray.PhoneNum!;
// 切圆
XNTool.viewCutRadius(iconImageView, cornerRadius: nil, borderWidth: 0, borderColor: nil);
// 属性设置
propertySet();
}
}
在tableView的showCell里创建cell,给cell的模型属性赋值即可