0

In my iPad app.i want to increment a label value when click a button.

enter image description here

actually label values are sending from previous view. so now i clicked a button but the last label value was incremented. see the below picture.

in the above picture i want to increment the label value in between the minus(-) and plus(+) buttons. but when i clicked plus button in first view but the label value is incremented on the third view.

 **  the above three views shown on the picture are sub viewed the scroll view **

i'm using this code......

-(IBAction)plusbutton:(id)sender
{
    val = [sender tag];
    NSLog(@"the_tag %d",val);
    itemref.countVal++;
    [self createOrderView];
}
4

1 回答 1

1

根据您的拳头,在该单个视图中为 - 和 + 按钮和标签提供相同的标签值,因此当单击按钮操作中的按钮时

    NSArray *subviews=[self.scrollview subviews];  
            for(UIView *sb_local in subviews)  
                    {  
                            if(sb_local.tag==[sender tag])
                            {    

                                 if([sb_local isKindOfClass:[UILabel class]])
                                {    
                                      UILabel *new_label=(UILabel *)[sb_local viewWithTag:pictag];  
                                      new_label.text = @"your value";
                                 //[new_label.text intValue]you get int value from that label.Increment or decrement that int value according your (+,-)button actions and assign again it to that label.
                                }

                             }
                    } 

请将此代码放在 ibaction + 和 - 按钮中 请为每个视图中的 + 和 - 按钮提供不同的操作

于 2013-02-28T11:31:19.320 回答