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.

lramirez135
  • 2,872
  • 3
  • 18
  • 18

1 Answers1

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!

  • 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. – lramirez135 Sep 28 '12 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. – Juan Munhoes Junior Sep 28 '12 at 14:47