【发布时间】:2014-09-17 11:36:20
【问题描述】:
我正在使用自定义单元格,其中有一个按钮,单击单元格时应将其标记为选中。但是当我单击一个单元格时,它会在表格中重复,例如。
单元格 1
单元格 2
单元格 3
单元格 4
单元格 5
单元格 6
单元格 7(从 1 开始重复检查)
单元格 8(从 2 处重复检查)
这是我的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
WIWNotificationViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WIWNotificationViewCell" forIndexPath:indexPath];
cell.notifySelected=NO;
if (cell == nil)
{
cell = [[WIWNotificationViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WIWNotificationViewCell"];
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WIWNotificationViewCell *cell = (WIWNotificationViewCell*)[tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell.notifySelected==YES)
{
[cell.btnNotifyClicked setSelected:NO];
cell.notifySelected=NO;
} else
{
[cell.btnNotifyClicked setSelected:YES];
cell.notifySelected=YES;
}
}
WIWNotificationViewCell 是一个自定义单元格,它包含要检查的 btnNotifiedClicked。
【问题讨论】:
-
您需要为它维护数据源,例如保留一个数组来跟踪它
-
怎么样?你能解释一下吗??
-
WIWNotificationViewCell的地址代码 - 您与btnNotifyClicked的联系方式 -
我只在自定义单元格中为 btnNotifyClicked 提供了一个出口。
标签: ios uitableview custom-cell