我在一个UITableView
. 每个单元格都有一组组件UIButton
,例如UILabel
和UISlider
。当我更新第 6 个单元格时,它反映到 1st cell
。同样,如果我更新第 7 个单元格,它会反映到第 2 个单元格。
我怎样才能防止这种情况?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return viewcount;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *MyIdentifier=@"mycell";
ListCell1 *cell = (ListCell1 *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[ListCell1 alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIButton *b=[buttonarray objectAtIndex:indexPath.row];
cell.imageView.frame=CGRectMake(0, 0, 0, 0);
b.imageView.frame=CGRectMake(0, 0, 30, 30);
cell.imageView.image=b.imageView.image;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
ListCell1 *cell1 = (ListCell1 *)[tableView cellForRowAtIndexPath:indexPath];
[cell1 addSubview:delbutton];
delpath=indexPath;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100.0;
}