iphone - 单击按钮时如何增加标签值

标签 iphone ios objective-c xcode ipad

在我的 iPad 应用程序中,我想在单击按钮时增加标签值。

enter image description here

实际上标签值是从之前的 View 发送的。所以现在我单击了一个按钮,但最后一个标签值增加了。见下图。

在上图中,我想增加减号(-)和加号(+)按钮之间的标签值。但是当我在第一个 View 中单击加号按钮时,但标签值在第三个 View 上增加。

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

我正在使用这个代码......

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

最佳答案

根据你的说法 首先在该单一 View 中为 - 和 + 按钮和标签提供相同的标签值,以便单击按钮时 在按钮操作中

    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 + 和 - 按钮中,请为每个 View 中的 + 和 - 按钮提供不同的操作

关于iphone - 单击按钮时如何增加标签值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133627/

相关文章:

ios - 在 swift iOS 中管理用户登录 segues

iphone - 分配 : *** error for object 0x165060: pointer being freed was not allocated?

iphone - UITableViewController 背景图片拉伸(stretch)

ios - ARKit - 扩展 "hitTest"的范围

objective-c - 使用MFMailComposeViewController发送邮件失败

iphone - 显示相机胶卷等选项的 View 的名称是什么?

iphone - 如何在 iOS 中将文本字符串转换为一组折线?

ios - 在 UIImageView 中剪裁的圆角

ios - 带有葫芦滑动的 UIPageViewController

objective-c - 在 Xcode 中分配基本数学运算结果时出现 "initializer element is not a compile-time constant"