在我的应用程序中我有1个图像视图和4个按钮,我想在其中一个按钮标题中显示图像名称,剩下的3个按钮应该显示其他标题,这里是我的代码代码,它不起作用,请帮忙我要解决
-(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;
}
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:@"imageName" forKey:@"button"];
[button setTitle:[artext objectAtIndex:value] forState:UIControlStateNormal];
}
}
}
}
答案 0 :(得分:2)
而不是:
[button setTitle:[artext objectAtIndex:value] forState:UIControlStateNormal];
试试这个:
[button setTitle:[NSString stringWithFormat:@"%@",[artext objectAtIndex:value]] forState:UIControlStateNormal];
还要确保[artext objectAtIndex:value]
确实包含一些值。