[tableView dequeueReusableCellWithIdentifier:@"identify"]

 

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 时候的代码放到外面来处理了

你可能感兴趣的:([tableView dequeueReusableCellWithIdentifier:@"identify"])