0

我正在尝试将一些为 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;

}

4

1 回答 1

0

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

于 2012-06-22T14:38:37.573 回答