gpt4 book ai didi

iphone - UITableView 滚动后更新自定义按钮图像

转载 作者:行者123 更新时间:2023-11-29 04:54:46 25 4
gpt4 key购买 nike

我正在努力访问一个自定义复选框,我已经在我的项目中将其用作自定义按钮,并尝试在我的 TableView 单元格中访问它。

目前,它正确提示按钮,并且工作得很好,除了当我滚动表格 View ,然后对按钮进行任何进一步更改( checkin 或 checkout )时,按钮图像将覆盖较旧的图像并且不更新绘图。

我只是好奇,这个问题有什么解决办法吗?

我的代码看起来像这样:

我的 cellForRowAtIndexPath 代码如下所示:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CustomTableCell";

CustomTableCell *cell = (CustomTableCell *)
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

[[NSBundle mainBundle] loadNibNamed:@"CustomTableCell"
owner:self options:nil];

cell = tableCell;

self.tableCell = nil;
}

CheckBox *chkBox = [[CheckBox alloc] init];
chkBox.frame = CGRectMake(10.0, -10.0, 50.0, 70.0);
[cell.contentView addSubview:chkBox];
[chkBox release];

cell.modelLabel.text =
[[[[[self regData] ShoppingCart] objectForKey:@"Cart"]
valueForKey:@"Model"] objectAtIndex:indexPath.row];

// Configure the cell...
return cell;
}

我还没有实现 didSelectRowAtIndexPath 方法,因为该方法应该将查看者带到包含更多信息的新屏幕。

最佳答案

您所做的是每次显示单元格时添加复选框,无论它是新单元格还是重复使用的单元格。

您不想每次都这样做:

CheckBox *chkBox = [[CheckBox alloc] init];
chkBox.frame = CGRectMake(10.0, -10.0, 50.0, 70.0);
[cell.contentView addSubview:chkBox];
[chkBox release];

仅当它是一个新单元格时才执行此操作...但是,通过将复选框添加为 subview 然后释放它,无论如何您都会失去对它的访问权限。要访问它,您需要迭代单元格的 subview ,找到类型复选框之一,然后查看它是否被选中。如果您的 CustomTableCell 有一个您设置的 Checkbox 属性,那就更好了,这样您就可以轻松访问它。

关于iphone - UITableView 滚动后更新自定义按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8217137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com