Iphone 帮助我复选框';s的复选标记被隐藏
请看我下面的代码片段。我将复选框放在我的手机中,我可以选中或取消选中复选框。但是当我滚动表格视图时,复选框的复选标记被隐藏。Iphone 帮助我复选框';s的复选标记被隐藏,iphone,uitableview,iphone-sdk-3.0,Iphone,Uitableview,Iphone Sdk 3.0,请看我下面的代码片段。我将复选框放在我的手机中,我可以选中或取消选中复选框。但是当我滚动表格视图时,复选框的复选标记被隐藏。 我的意思是通过设置图像来设置复选标记 请任何人帮我解决这个问题 谢谢你抽出时间 // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)i
我的意思是通过设置图像来设置复选标记 请任何人帮我解决这个问题 谢谢你抽出时间
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"en"] autorelease];
cb = [[UIButton alloc] initWithFrame:CGRectMake(5,10, unselectedImage.size.width, unselectedImage.size.height)];
[cb setImage:unselectedImage forState:UIControlStateNormal];
[cb setImage:selectedImage forState:UIControlStateSelected];
[cb addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:cb];
}
if ( tableView == myTableView )
{
titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, 150, 35)];
titleLabel.font = [UIFont boldSystemFontOfSize:13];
titleLabel.textColor = [UIColor blackColor];
[cell.contentView addSubview:titleLabel];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
取自
如果我正确理解TableView的概念,您需要将复选标记设置保存到其他地方。如果您的单元格被滚动出视图,TableViewController可能会释放该单元格。然后,当要求您在代理中重新创建单元格时,您必须将其恢复到与以前相同的状态。在
DidSelectRowAtindexPath
中:
if ([set containsObject:indexPath])
{
[set removeObject:indexPath];
}
else
{
[set addObject:indexPath];
}
if ([set containsObject:indexPath])
{
cell.imgView.image=[UIImage imageNamed:@"chealBox1.png"];
}
else
{
cell.imgView.image=[UIImage imageNamed:@"chealBox2.png"];
}
而在单元格中,则为rpwatindexpath
:
if ([set containsObject:indexPath])
{
[set removeObject:indexPath];
}
else
{
[set addObject:indexPath];
}
if ([set containsObject:indexPath])
{
cell.imgView.image=[UIImage imageNamed:@"chealBox1.png"];
}
else
{
cell.imgView.image=[UIImage imageNamed:@"chealBox2.png"];
}
这里的集合是NSMutableSet
,您必须在viewDidLoad中创建属性、合成和分配…肯定会工作