Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableviewcell内容更新反映到其他单元格_Iphone_Ios_Uitableview - Fatal编程技术网

Iphone UITableviewcell内容更新反映到其他单元格

Iphone UITableviewcell内容更新反映到其他单元格,iphone,ios,uitableview,Iphone,Ios,Uitableview,我在tableview中使用了8个单元格。每个单元格都有一组组件,如UIButton、UILabel和UISlider。当我更新第6个单元格时,它会反射到第1个单元格。类似地,如果我更新第7个单元格,它将反映到第2个单元格 删除单元格代码: { [buttonarray removeObjectAtIndex:delpath.row]; viewcount--; ListCell1 *cell=(ListCell1 *)[table cellForRowAtIndexPath:delpat

我在tableview中使用了8个单元格。每个单元格都有一组组件,如UIButton、UILabel和UISlider。当我更新第6个单元格时,它会反射到第1个单元格。类似地,如果我更新第7个单元格,它将反映到第2个单元格

删除单元格代码:

{
 [buttonarray removeObjectAtIndex:delpath.row];
 viewcount--;

ListCell1 *cell=(ListCell1 *)[table cellForRowAtIndexPath:delpath];

cell.slider.value=0;
cell.qlabel.text=@"1";
cell.slabel.text=@"1";
cell.n=1;
[cell.button1 setTitle:@"240" forState:UIControlStateNormal];


for (int m=0; m<7; m++)
{
    [[cell.myarray objectAtIndex:m]setImage:[UIImage imageNamed:@"Num2.png"] forState:UIControlStateNormal];
    UIButton *but=[cell.myarray objectAtIndex:m];
    but.tag=0;
}

 [self->table deleteRowsAtIndexPaths:[NSArray arrayWithObjects:delpath, nil]     withRowAnimation:UITableViewRowAnimationFade];
[table reloadData];
delpath=NULL;
}
tableview的代码

-(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;
 return;
 }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100.0;
}

发生此问题的原因是UIKit在UITableView中重复使用单元格。因此,当您向该单元格添加UI组件时,相同的组件将在不同的行上重复使用


简而言之,你需要在每次更新单元格时清除/重建你的UI。

与Xcode无关。哈哈…对不起,我不明白你的代码:(所以请..输入更清晰的代码:)谢谢:)你能给我一个在单元格中添加comp的示例代码,以及如何在不改变值的情况下删除该单元格吗?请提供以下代码:(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath?检查问题我现在通过编辑添加了它。我在这里遇到了相同的问题。那么我如何以编程方式解决它
-(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;
 return;
 }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100.0;
}