Cocoa touch UIButton的UIImageView不会更改
我有以下行动Cocoa touch UIButton的UIImageView不会更改,cocoa-touch,uibutton,uiimage,Cocoa Touch,Uibutton,Uiimage,我有以下行动 . . if(!isWishlisted) { isWishlisted = true; plistPath = [[NSBundle mainBundle] pathForResource:@"InYourWishlist" ofType:@"png"]; addToWishListButton.imageView.image = [UIImage imageWithContentsOfFil
.
.
if(!isWishlisted)
{
isWishlisted = true;
plistPath = [[NSBundle mainBundle] pathForResource:@"InYourWishlist" ofType:@"png"];
addToWishListButton.imageView.image = [UIImage imageWithContentsOfFile:plistPath];
NSLog(@"Set Image with InYourWishlist");
}
else
{
isWishlisted = false;
plistPath = [[NSBundle mainBundle] pathForResource:@"Add to Wishlist" ofType:@"png"];
addToWishListButton.imageView.image = [UIImage imageWithContentsOfFile:plistPath];
NSLog(@"Set Image with Add To Wishlist");
}
.
.
最初,在视图加载时,执行一次
isWishlisted = false;
在“mainSoryBoard”上,“addToWishListButton”的图像设置为“addtoWishList.png”
在前两次单击(相隔几秒钟)时,我得到以下日志输出:
2012-10-28 21:16:28.420 Movie Rental[92512:c07] Set Image with InYourWishlist
2012-10-28 21:16:31.596 Movie Rental[92512:c07] Set Image with Add To Wishlist
但问题是,按钮上的图像“InYourWishlist.png”会出现一瞬间,然后会变回上一个图像
有什么问题吗?代码中没有其他地方可以访问“addToWishListButton”按钮。使用
[addToWishListButton setImage:[UIImage imageWithContentsOfFile:plistPath] forState:UIControlStateNormal];