滚动 tableview 计数标签值是否已更改? [英] Scrolling the tableview count label value is changed?

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

问题描述

 - (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;
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 计数会增加.问题是当我的 tableview 滚动时,countlabel 变为零.

This is my code when I click the PlusButtonSelect count will be increased. The problem is when my tableview scrolls, the countlabel becomes zero.

推荐答案

终于找到答案了,这里 myData 是 NsMutableArray.首先基于 No of Row 我们可以在 myData 中取第一个零.在 cellForRowAtIndexPath

Finally i find an answer,Here myData is NsMutableArray. First based on No of Row we can take the first Zero's in myData. in 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.text=[NSString stringWithFormat:@"%@",[myData objectAtIndex:indexPath.row]];

        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];
  [myData replaceObjectAtIndex:sender.tag withObject:Strcount];
  [tableview reloadData];

}

减号按钮也一样.

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

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