gpt4 book ai didi

ios - 访问在运行时创建的UILabel

转载 作者:行者123 更新时间:2023-12-01 17:51:19 24 4
gpt4 key购买 nike

我已经在UILabel (lblCount)的action方法上创建了UIButton (btnAdd)UIButton (Add Item Button)。新的UILabelUIButton已添加到scrollview中。 UILabel (lblCount)显示被点击的UIButton (btnAdd)的数量。在这里,addBtnClickCount是一个整数,用于计算点击次数。

    UILabel * lblCount = [[UILabel alloc] initWithFrame:CGRectMake( 50, 100*addBtnClickCount, 25, 25)];
lblCount.text = [NSString stringWithFormat:@"%d",count];
lblCount.tag = addBtnClickCount;
lblCount.textColor = [UIColor whiteColor];
lblCount.textAlignment = NSTextAlignmentCenter;
[self.scrollView addSubview:lblCount];

addBtnClickCount = addBtnClickCount+1;

当用户点击添加项目按钮时,将有多个 label (lblCount)button (btnAdd)。我想访问特定 labeladd button的特定 display the count

最佳答案

您已经在标签上设置了标签。创建一个可变数组labelArray并为其添加标签。要访问特定标签,请在“添加”按钮的操作上执行以下代码。

       -(void)addItem:(UIButton*)button{
UILabel* lblShowCount = [_labelArray objectAtIndex:[button tag]];
lblShowCount.text = [NSString stringWithFormat:@"%d", [lblShowCount.text integerValue]+1];

}

关于ios - 访问在运行时创建的UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com