gpt4 book ai didi

iphone - 每次点击 4 个按钮标题更改

转载 作者:行者123 更新时间:2023-11-28 22:46:42 24 4
gpt4 key购买 nike

我的应用程序中有四个按钮,我从数组中获取按钮标题,我想在每次单击任何按钮时更改 4 个按钮标题,但这里单击的按钮标题只更改了,这里是我的代码,

-(IBAction)setting:(id)sender
{
int value = rand() % ([arraytext count] -1) ;
UIButton *mybuton = (UIButton *)sender;
[mybuton setTitle:[arraytext objectAtIndex:value] forState:UIControlStateNormal];
}

已更新

-(IBAction)answersetting:(id)sender
{

UIButton *mybutton = (UIButton *)sender;
static int j = 0;
if(sender == mybutton)
j++;
if (j >= arcount)
{
j = 0;
}
else if(j < 0)
{
j = arcount - 1;
}

CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.type = kCATruncationMiddle;

[animage.layer addAnimation:transition forKey:nil];
animage.image=[arimage objectAtIndex:j];

for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UIButton class]])
{
UIButton *button = (UIButton *)view;
if(button.tag == 1||button.tag == 2||button.tag == 3||button.tag == 4)
{
int value = rand() % ([artext count] -1) ;
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:animage.image forKey:@"button"];
[button setTitle:[artext objectAtIndex:value] forState:UIControlStateNormal];

}
}
}

我将此方法与 4 个按钮连接,我想在单击任何按钮时更改所有按钮标题,请帮助编码

最佳答案

因为 sender 只持有您点击的那个 UIButton
要更改所有 UIButton 的标题,您需要一个循环。
tag 设置为所有 4 个 buttons

然后这样做-

-(IBAction)setting:(id)sender
{
int value = rand() % ([arraytext count] -1) ;
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UIButton class]])
{
UIButton *button = (UIButton *)view;
if(button.tag == 1||button.tag == 2||button.tag == 3||button.tag == 4)
{
[button setTitle:[arraytext objectAtIndex:value] forState:UIControlStateNormal];
}
}
}
}

关于iphone - 每次点击 4 个按钮标题更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13046816/

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