- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath;
{
static NSString *simpleTableIdentifier = @"ickAClassCell";
cell = (PickAClassCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed"ickAClassCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.CountLabel.tag=1000;
return cell;
}
-(void)PlusButtonSelect UIButton *)sender
{
UILabel *label1 = (UILabel *)[sender.superview viewWithTag:1000];
int count = [label1.text intValue];
count = count + 1;
label1.text = [NSString stringWithFormat"%d",count];
NSLog(@"%@",label1);
}
这是我的代码,当我单击 PlusButtonSelect 时计数会增加。问题是当我的表格 View 滚动时,计数标签变为零。
Best Answer-推荐答案 strong>
终于找到答案了,这里的myData 是NsMutableArray。首先基于 No of Row 我们可以取 myData 中的第一个零。
在 cellForRowAtIndexPath
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath;
{
static NSString *simpleTableIdentifier = @"ickAClassCell";
cell = (PickAClassCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed"ickAClassCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.CountLabel.text=[NSString stringWithFormat"%@",[myData objectAtIndex:indexPath.row]];
cell.CountLabel.tag=1000;
[cell.PlusCount addTarget:self actionselector(PlusButtonSelect forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(void)PlusButtonSelect UIButton *)sender
{
UILabel *label1 = (UILabel *)[sender.superview viewWithTag:1000];
NSLog(@"%@",label1);
int count = [label1.text intValue];
count = count + 1;
NSString *Strcount= [NSString stringWithFormat"%d",count];
[myData replaceObjectAtIndex:sender.tag withObject:Strcount];
[tableview reloadData];
}
减号按钮也一样。
关于ios - 滚动tableview计数标签值改变了吗?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/41057554/
|