Iphone 每次单击时4个按钮标题更改

Iphone 每次单击时4个按钮标题更改,iphone,ios,uibutton,nsmutablearray,Iphone,Ios,Uibutton,Nsmutablearray,我的应用程序中有四个按钮,我从数组中获取按钮标题,我想在单击任何按钮时更改这四个按钮标题,但这里单击的按钮标题仅更改,这里是我的代码 -(IBAction)setting:(id)sender { int value = rand() % ([arraytext count] -1) ; UIButton *mybuton = (UIButton *)sender; [mybuton setTitle:[arraytext objectAtIndex:value] forState:UICont

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

-(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];

        }
    }
}
-(iAction)应答设置:(id)发送方
{
UIButton*mybutton=(UIButton*)发送方;
静态int j=0;
如果(发送方==mybutton)
j++;
如果(j>=arcount)
{
j=0;
}
else如果(j<0)
{
j=弧计数-1;
}
CATTransition*转换=[CATTransition动画];
过渡时间=1.0f;
transition.timingFunction=[CamediaTimingFunctionWithName:kCAMediaTimingFunctionEaseOut];
transition.type=kCATruncationMiddle;
[animage.layer addAnimation:transition-forKey:nil];
animage.image=[arimage objectAtIndex:j];
for(UIView*self.view.subview中的视图)
{
if([view IsKindof类:[UIButton类]])
{
UIButton*按钮=(UIButton*)视图;
如果(button.tag==1 | | | button.tag==2 | | | button.tag==3 | | button.tag==4)
{
int value=rand()%([artext count]-1);
NSMutableDictionary*dictionary=[[NSMutableDictionary alloc]init];
[字典设置值:animage.image forKey:@“按钮”];
[按钮设置标题:[artext objectAtIndex:value]用于状态:UIControlStateNormal];
}
}
}
}


我用4个按钮连接此方法,每当我单击任何按钮时,我想更改所有按钮标题,请帮助编码,因为
sender
仅保存您单击的
ui按钮。
要更改所有
ui按钮的标题,您需要一个循环。
标记设置为所有4个
按钮

那就这样做吧-

-(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];
            }
        }
     }  
}

您需要将所有这些UIButton保存在数组中,然后您可以在单击事件中更改所有这些UIButton的标题。@SHAZAD您可以通过代码进行解释吗?如果我有另一个图像数组,如何在UIButton中将图像名称显示为标题制作图像名称数组,然后您可以从数组中获取它们。我的疑问是,如果我选择的按钮包含uiimage视图中的相同图像?我没有正确地理解您。您有一种方法可以单击所有按钮。。。那么你的imageView做得怎么样?我在问我是否放置了一个包含图像的数组,以及是否将按钮的标题显示为图像名称…我如何继续进行tat?