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