滚动 tableview 时更改计数值 [英] Count value is changed when tableview is scrolling

查看:30
本文介绍了滚动 tableview 时更改计数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的CellForRowAtIndexPath代码

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{


static NSString *simpleTableIdentifier = @"PickAClassCell";

cell = (PickAClassCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PickAClassCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];

}
cell.CountLabel.tag=1000;
[cell.PlusCount addTarget:self action:@selector(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];



    label1.text=Strcount;
}

当我单击加号按钮时,计数值会增加,但我的问题是当我滚动 tableview 时,添加的计数值为零(默认位置).

when i click the plus button count value is increased but my problem is when i scrolling the tableview added count value goes to zero (default position).

推荐答案

cellForRowAtIndexPath

if ([self.selectedRows containsObject:indexPath])
{
    // set count values here 
    cell.countLabel.text = @"";
    cell.textLabel.textColor = [UIColor grayColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
    //set the normal cells values
}

这里的 self.selectedRows 是一个数组,当用户点击加号或减号按钮时,你必须在其中存储 cellIndexPath 值.

Here self.selectedRows is an array where you have to store cellIndexPath values when user clicked plus or minus button.

这篇关于滚动 tableview 时更改计数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆