【发布时间】:2013-01-11 12:24:10
【问题描述】:
我在表格视图中使用了 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;
}
按下按钮时
-(void)buttonpressed:(id)sender
{
viewcount++;
table.delegate=self;
table.dataSource=self;
//UIView *middleview=[[UIView alloc]initWithFrame:CGRectMake(100,200,300,200)];
[buttonarray addObject:sender];
[table reloadData];
}
表格视图代码
-(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;
}
【问题讨论】:
-
与 Xcode 无关。
-
哈哈...对不起,我不明白你的代码:(所以请..输入更清晰的代码:)谢谢:)
-
你能给我一个在单元格中添加 comp 的示例代码以及如何在不更改任何值的情况下删除该单元格
-
你能提供代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 吗?
-
检查有问题我现在通过编辑添加了它。
标签: iphone ios uitableview