• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IOS development, problems with setting uibutton image

 
Susana Brown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell me what is wrong with this code?

Only the else part is not working, if I have an image for the note, every thing is working just perfect, but when i am trying to show the "no_image" image, i just don't see it (there is not error). Looks like a "nil", but the image is in the project, for sure. i am using the same image in other places and other methods and it is working over there. just in the UIButton not working.

//setting the note header data
if (note.imageThumb) {
[photoButton setImage:note.imageThumb forState:UIControlStateNormal];
} else {
[photoButton setImage:[UIImage imageNamed:@"no_image.png"] forState:UIControlStateNormal];
}
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it has been a little while, but.

1) Are you sure the image is added correctly to the project, so it knows where it is located automatically?
2) Have you tried instantiating the Image on a separate line so you an better debug the root cause.
Is it [UIImage imageNamed:@"no_image.png"]
or
forState:UIControlStateNormal];
or
[photoButton setImage:

The last two I probably would look at together. But because you put it all in one line makes it tougher to figure out what is wrong, or what is really causing the problem.

Is the "@" supposed to be inside the quotes in the code???

Also we have a code button for posting code to this forum so that it keeps its indentation and makes it more readable. Now you just have 5 lines so no big deal, but for the future posts.

Thanks

Mark
 
Susana Brown
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did check what you suggested. It run well now. Thank you!
 
julia arvil
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't know why you can do it, but i can't. is it out of date or something
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic