在我看来,我有 1 个UIimageview
和 4 个UIButton
,我展示了来自NSMutableArray
. 如何在UIButton
没有图像视图图像名称的情况下将标题显示为.png
?我尝试使用以下编码
imageary=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"dear.jpg"],[UIImage imageNamed:@"donkey.jpg"],[UIImage imageNamed:@"elephant.jpg"],[UIImage imageNamed:@"fox.jpg"],[UIImage imageNamed:@"giraffe.jpg"],[UIImage imageNamed:@"goat.jpg"],[UIImage imageNamed:@"buffallo.jpg"],[UIImage imageNamed:@"bull.jpg"],[UIImage imageNamed:@"cow.jpg"],[UIImage imageNamed:@"crocodile.jpg"], nil];
- (NSString *) convertToDisplayName:(NSString *)actual
{
return [actual stringByReplacingOccurrencesOfString:@".png" withString:@" "];
}
尝试使用上述方法检索名称时
int i=0;
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UIButton class]])
{
mybutton = (UIButton *)view;
if(mybutton.tag == 1||mybutton.tag == 2||mybutton.tag == 3||mybutton.tag == 4)
{
animage.image=[imageary objectAtIndex:i];
name=[self convertToDisplayName:[imageary objectAtIndex:i]];
[mybutton setTitle:name forState:UIControlStateNormal];
NSLog(@"current image name :%@",name);
i++;
}
}
}
它显示错误
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x73f8eb0
请帮助我必须纠正的地方。