如何转换此NSImage代码以在iOS上使用

时间:2012-06-22 14:30:53

标签: iphone ios macos uiimageview nsimage

我正在尝试将为Mac OS X编写的代码转换为iOS应用程序。这是OS X的工作代码:

// To create the images on the view:
NSRect imageRect = NSMakeRect(24+(i*80), ypos, 72, 96);
    NSImageView *theImageView=[[NSImageView alloc] initWithFrame:imageRect];
    [theImageView setBounds:imageRect];
    [self addSubview:theImageView];
    [theImageView setImage:[tCard image]];
    [self.imageviews addObject:theImageView];

// To remove the images on the view:
    for (NSImageView *timageview in self.imageviews) {
    [timageview removeFromSuperview];
}
[self.imageviews removeAllObjects];

目前,我有:

//To create the image on the view
UIImageView * theImageView = [[UIImageView alloc] initWithFrame:CGRectMake(24+(i*80), ypos, 72, 96)];
    [self addSubview:theImageView];
    [theImageView setImage:[tCard image]];
    [self.imageviews addObject:theImageView];

// To remove the images on the view:
 for (UIImageView *timageview in self.imageviews) {
    [timageview removeFromSuperview];
}
[self.imageviews removeAllObjects];

然而!删除图像工作。图像在视图上显示正常,但我无法删除它们。说实话,我并不是100%确定示例代码是如何完全正常工作的,但是我正在破解并试图解决它,因此为什么我似乎有点中途,但无法得到要删除的图片:'(

感谢您的以下输入!如有任何问题或需要更多信息,请与我们联系。

编辑:这是self.imageviews初始化的方式:

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
    self.imageviews = [[NSMutableArray alloc] initWithCapacity:4]; 
}
return self;

}

1 个答案:

答案 0 :(得分:0)

正如猜测一样,我认为关键是self.imageviews。我猜你没有初始化它。在某处你应该有类似self.imageviews = [[NSMutableArray alloc] init];的东西。