1

I have a custom button with an image. I had to change the image so I deleted the old one and placed a new one with the same name into my project. But now, no image appears for the button, but if I click on the button it works fine. Here is the code:

//before @implementation 
static NSString *kdetailsIcon = @"details.png";

//in a helper method
UIButton *detailsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[detailsButton setFrame:CGRectMake(276, 8, 44, 44)];
[detailsButton setImage:[UIImage imageNamed:kdetailsIcon] forState:UIControlStateNormal];
[detailsButton addTarget:self action:@selector(showDetailView) forControlEvents:UIControlEventTouchUpInside];
[infoBar addSubview:detailsButton];

I figure the problem is actually something with xcode rather than my code, but I have tried deleting the image files and re-adding them, cleaning the project, deleting the app from my phone before compiling, deleting the derived data, everything I can think of. Any help would be greatly appreciated.

4
  • case sensitive? e.g is your new image "Details.png" Sep 28, 2012 at 12:58
  • no, already looked into that :/ Sep 28, 2012 at 13:00
  • why to use like that you want tochange the button image when u click on the button is it u r requirement or any other
    – 08442
    Sep 28, 2012 at 13:04
  • clean your project and add the image in such situations. Then make a clean and build.
    – Midhun MP
    Sep 29, 2012 at 9:24

1 Answer 1

3

-First make a clean in your project click in product/clean.

-Delete this image from directory of your project in Xcode. Them add this image into your paste project. Go to XCode again, in your project go File / Add Files to project_Name.

search and choose your image and sucess. If not Success,Close/Open Project again.if not sucess again your writing wrong name/extensions of your image!

2
  • Thank you, this actually worked. Any chance you could explain why though? Because it doesn't really make sense. Before trying this approach I had deleted the images, dragged in the new one to the folders, cleaned and run. Do you have to close xcode every time you do this or something? Thanks again. Sep 28, 2012 at 13:23
  • xcode sometimes generates some bugs, but i think in your case you put an image into your project and change the image directory, so the image apears in your project but actually its not found the correctly directory image. So when you want to put something in your project always copy to your paste project and them in XCode import to your project. Sep 28, 2012 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.