【问题标题】:Adding image programmatically in view在视图中以编程方式添加图像
【发布时间】:2011-11-10 21:13:48
【问题描述】:

我以编程方式在视图中添加了图像。但是当我切换到使用代码查看添加图像的位置时,我的应用程序已中止

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 我取自之前的主视图。

【问题讨论】:

  • CountryFalgImage 是一个属性吗?我发现有点怀疑 stringWithString: 行。更好的是我不明白你想要做什么......
  • CountryFlagImage 是在你的头文件中声明的实例变量吗?
  • 你的堆栈跟踪说什么?

标签: objective-c view sdk


【解决方案1】:

看起来是保留问题...尝试保留 CountryFlagImage 可能在您使用之前已发布。

【讨论】:

  • 控制台显示2011-11-12 19:55:57.226 EuroCountries[4967:207] -[UIImageView text]: unrecognized selector sent to instance 0x4b1b940 2011-11-12 19:55:57.357 EuroCountries[4967:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView text]: unrecognized selector sent to instance 0x4b1b940'terminate called after throwing an instance of 'NSException' 保留CountryFlagImage 没有给出任何结果。
猜你喜欢
  • 2015-08-24
  • 2012-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多