我有一个带图像的自定义按钮。我不得不更改图像,所以我删除了旧图像,并在我的项目中添加了一个具有相同名称的新图像。但是现在,按钮没有显示图像,但如果我点击按钮就可以了。这是代码:
//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];
我认为问题实际上是xcode而不是我的代码,但我尝试删除图像文件并重新添加它们,清理项目,在编译之前从手机中删除应用程序,删除派生数据,一切我能想到。任何帮助将不胜感激。
答案 0 :(得分:3)
- 首先在项目中清理产品/清洁。
- 在Xcode中从项目目录中删除此图像。他们将此图像添加到您的粘贴项目中。再次转到XCode,在项目中将文件/添加文件添加到project_Name。
搜索并选择您的图像和成功。如果不是成功,请再次关闭/打开项目。如果再次成功,则写入错误的图像名称/扩展名!