[tableView dequeueReusableCellWithIdentifier:@"identify"]

本文介绍如何在UITableView中为单元格(cell)设置文本和图标,并确保它们的位置正确无误。通过检查cell是否为空来避免布局偏移的问题,同时展示了如何根据用户设置的状态改变cell内标签的内容。

 

cell = [tableView dequeueReusableCellWithIdentifier:@"identify"];

if ( cell == nil )

{

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"identify"] autorelease];

cell.text = _(PASSWORDLOCK);

cell.textAlignment = UITextAlignmentLeft;

cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

statelabel = [ [ UILabel alloc ] initWithFrame:CGRectMake(235, cell.frame.origin.y+3, 60, cell.frame.size.height-10) ];

userDefaults = [ NSUserDefaults standardUserDefaults ];

if ( [ userDefaults objectForKey:PASSWORD ] )

{

statelabel.text = _(OPEN);

}

else

{

statelabel.text = _(CLOSE);

}

statelabel.textColor = [ UIColor colorWithRed:0.18 green:0.39 blue:0.73 alpha:1 ];

statelabel.tag = PASSWORD_STATE;

[ cell.contentView addSubview:statelabel ];

[ statelabel release ];

}

有时刷新后发现cell中文本或者图片位置发生偏移 主要是把cell !=nil 时候的代码放到外面来处理了

1>moc_TableView.obj : error LNK2005: "public: virtual struct QMetaObject const * __cdecl TableView::metaObject(void)const " (?metaObject@TableView@@UEBAPEBUQMetaObject@@XZ) 已经在 TableView.obj 中定义 1>moc_TableView.obj : error LNK2005: "public: virtual void * __cdecl TableView::qt_metacast(char const *)" (?qt_metacast@TableView@@UEAAPEAXPEBD@Z) 已经在 TableView.obj 中定义 1>moc_TableView.obj : error LNK2005: "public: virtual int __cdecl TableView::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@TableView@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z) 已经在 TableView.obj 中定义 1>moc_TableView.obj : error LNK2005: "private: static void __cdecl TableView::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@TableView@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z) 已经在 TableView.obj 中定义 1>moc_TableView.obj : error LNK2005: "public: static struct QMetaObject const TableView::staticMetaObject" (?staticMetaObject@TableView@@2UQMetaObject@@B) 已经在 TableView.obj 中定义 1>bzdbs.obj : error LNK2019: 无法解析的外部符号 "public: __cdecl CBaseData::CBaseData(class QObject *)" (??0CBaseData@@QEAA@PEAVQObject@@@Z),函数 "public: __cdecl CBZDBS::CBZDBS(void)" (??0CBZDBS@@QEAA@XZ) 中引用了该符号 1>cdcbtn.obj : error LNK2001: 无法解析的外部符号 "public: __cdecl CBaseData::CBaseData(class QObject *)" (??0CBaseData@@QEAA@PEAVQObject@@@Z) 1>cl.obj : error LNK2001: 无法解析的外部符号 "public: __cdecl CBaseData::CBaseData(class QObject *)" (??0CBaseData@@QEAA@PEAVQObject@@@Z)
11-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值