我的应用程序中有四个按钮,我从数组中获取按钮标题,我想在单击任何按钮时更改 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 个按钮连接,我想在单击任何按钮时更改所有按钮标题,请帮助编码