0

在我的应用程序中,我有 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];

        }
    }
}

}
4

1 回答 1

2

代替:

[button setTitle:[artext objectAtIndex:value] forState:UIControlStateNormal];

试试这个:

[button setTitle:[NSString stringWithFormat:@"%@",[artext objectAtIndex:value]] forState:UIControlStateNormal];

还要确保[artext objectAtIndex:value]确实包含一些价值。

于 2012-10-29T10:18:21.657 回答