即時消息在我的應用程序中有四個按鈕,即時獲取數組中的按鈕標題,每當我點擊任何按鈕時,我都想更改4個按鈕標題,但是這裏點擊的按鈕標題只是改變了在這裏我的代碼,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個按鈕連接這種方法,我想改變這一切的按鈕標題每當我點擊任何按鈕,請幫助編碼
您需要保存在陣列中的所有這些uibuttons則u可以單擊事件改變所有這些標題。 – jamil
@SHAZAD可以通過代碼解釋嗎? – Fazil