以编程方式在视图中添加图像
我以编程方式在视图中添加了图像。但是当我切换到查看添加图像的位置时,我的应用程序已中止
UIImageView *countryFlag = [[UIImageView alloc] initWithImage:[UIImage imageNamed:CountryFlagImage]];
[countryFlag setFrame:CGRectMake(0, 0, 50, 50)];
[self.view addSubview:countryFlag];
[countryFlag release];
countryFlag = nil;
- (id)initWithNibName 我有
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil CountryFlagImage:(NSString*)imageFlagName
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
CountryFlagImage = [NSString stringWithString:imageFlagName];
}
return self;
}
从以前的主视图中获取的 CountryFlagImage。
I added image in my view programmatically. But my app has aborted when I switch to view where added image with code
UIImageView *countryFlag = [[UIImageView alloc] initWithImage:[UIImage imageNamed:CountryFlagImage]];
[countryFlag setFrame:CGRectMake(0, 0, 50, 50)];
[self.view addSubview:countryFlag];
[countryFlag release];
countryFlag = nil;
In - (id)initWithNibName I have
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil CountryFlagImage:(NSString*)imageFlagName
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
CountryFlagImage = [NSString stringWithString:imageFlagName];
}
return self;
}
CountryFlagImage I took from previous main view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来像是保留问题...尝试保留
CountryFlagImage
也许在您可以使用它之前已被释放。Looks like a retain problem... try retaining
CountryFlagImage
maybe is being released before you can use it.