gpt4 book ai didi

iphone - Objective-C : UIButton image does not changes

转载 作者:搜寻专家 更新时间:2023-10-30 19:46:30 24 4
gpt4 key购买 nike

我这样做是为了更改UIButton 图像,这里所有的“开关” 都是UIButtonIBOutlets ,

-(IBAction)userselect:(id)sender
{
UIButton *btnTagcatcher =(UIButton * )sender;
if(btnTagcatcher.tag == 1)
{
if(btnimgflag1 == 0)
{
NSString* path = [[NSBundle mainBundle] pathForResource:@"check-box-withtick-1n1"
ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
[switch1 setImage:image forState:UIControlStateNormal];
NSString* path1 = [[NSBundle mainBundle] pathForResource:@"check-box-withouttickn1"
ofType:@"png"];
UIImage *image1 = [[UIImage alloc] initWithContentsOfFile:path1];
[switch2 setImage:image1 forState:UIControlStateNormal];
[switch3 setImage:image1 forState:UIControlStateNormal];
[switch4 setImage:image1 forState:UIControlStateNormal];
btnimgflag2 = 0;
btnimgflag3 = 0;
btnimgflag4 = 0;


btnimgflag1 = 1;
}
else if(btnimgflag1 == 1)
{
NSString* path = [[NSBundle mainBundle] pathForResource:@"check-box-withouttickn1"
ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];

//[switch1 setImage: image];
[switch1 setImage:image forState:UIControlStateNormal];
btnimgflag1 = 0;
}

但有些时候(通常是第一次按下时)点击时按钮图像不会改变。

我不知道,请问这里发生了什么。提前指导我,thanx。

问候萨德。

最佳答案

您能否将此条件 else if(btnimgflag1 == 1) 更改为简单的 else 语句。因为在 if 部分中,您将 btnimgflag1 指定为 1 btnimgflag1 = 1;。只是我的猜测,我遇到了完全相同的问题!如果那没有帮助! IBOutlet connections 应该是问题所在!!

关于iphone - Objective-C : UIButton image does not changes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11823382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com