我是iPhone开发新手。我应该在哪里把我的图片放在我的iPhone项目中?
现在我有一个项目,它的目录结构如下:
Tutorial
\__Tutorial\
\__1.png
\__TutorialViewController.h
\__TutorialViewController.m
\__TutorialViewController.xib
\__Supporting Files\
\__Frameworks\
\__Products\
我试图用[UIImage的imageNamed:@“1.png”]来渲染视图图像:
UIImage *image = [UIImage imageNamed:@"1.png"];
imageView.image = image;
[image release];
但图像没有显示出来。
所以我想知道我应该把图像放在哪里?
此外,如果我有很多图像(如1000号),应该怎么做?
这里是我的代码:
#import "TutorialViewController.h"
@implementation TutorialViewController
@synthesize labelText;
@synthesize imageView;
-(void) click:(id)sender {
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSString *newText = [[NSString alloc]initWithFormat:@"%@",titleOfButton];
// Change Image When Clicking Color Button
if([titleOfButton isEqualToString:@"Blue"]){
NSLog(@"Blue");
imageView.image = [UIImage imageNamed:@"a.png"];
}else{
imageView.image = [UIImage imageNamed:@"b.png"];;
NSLog(@"Else");
}
labelText.text = newText;
[newText release];
}
如果您之前未分配图像,则无法释放图像。你如何管理imageView?通过代码或xib? –
没有[UIImage imageNamed:@“1.png”]分配内存本身?我的imageView被定义为一个IBOutlet并从xib连接到FileOwner。 – MrROY
@SimonePistecchia我不分配它,但它不会抛出异常..... – MrROY