【发布时间】:2012-10-29 07:30:31
【问题描述】:
在我的应用程序中,我有 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];
}
}
}
}
【问题讨论】:
-
UIButton *mybutton = (UIButton *)sender; ..if(sender == mybutton) 我觉得这个if语句没用。
-
@KevinCao 我用它在点击时显示下一张图片
-
@fasilmoham:你能把你的问题说得更清楚吗?
-
在我看来,我有 1 个图像视图和 4 个按钮,我在图像视图中从数组中显示图像,因为我想将 1 个按钮标题显示为当前图像名称,其余按钮作为不同名称数组。我无法在按钮标题中显示图像当前图像名称,你能帮我解决@VenkatManohar
-
@fasilmoham:按钮标题应该是什么......就像你在其他地方保存图像名称一样?
标签: iphone ios uiimageview uibutton