UIImageView's image dont change by code
I know that my problem is stupid but i'm not able to fix it and i didn't find any answer. I have an IBoutlet UIImageView in a Custom UITableViewCell. I set it's UIImage in IB and i want to change it by code when the custom cell is taped. My code is as follow. But somehow image is not changing. This is a method from my custom UItableViewCell.
-(void)setExpanded:(BOOL)expand
{
if(expan开发者_运维技巧d)
{
[self.expandedImageView setImage:[UIImage imageNamed:@"bt_up.png"]];
expanded = YES;
//self.infoLabel.hidden = NO;
//[self setNeedsDisplay];
}
else
{
[self.expandedImageView setImage:[UIImage imageNamed:@"bt_down.png"]];
expanded = NO;
//self.infoLabel.hidden = YES;
//[self setNeedsDisplay];
}
}
I tried to play with "SetNeedDisplay". I also tried to change the UIimage outside of the CustomCell but dont works.
Any help will be very appreciated because i'm on it since so much time ;)
regards,
There could be 2 possible reasons:
- Your self.expandedImageView is nil
- You don't have images named bt_up.png, bt_down.png
If your image and properties really are valid, then I'd suggest checking which thread is calling setExpanded:
. Cocoa states that UI objects should only be modified by the UI thread, so if you're invoking it from some timer or BG thread then maybe that's the issue.
Try printing its (custom UITableViewCell) subviews and check if the image instance exists or not in the list, if exists try changing image for that instance.
精彩评论