【问题标题】:How to transform this NSImage code for use on iOS如何转换此 NSImage 代码以在 iOS 上使用
【发布时间】:2012-06-22 14:30:53
【问题描述】:

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

}

【问题讨论】:

    标签: iphone ios macos uiimageview nsimage


    【解决方案1】:

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

    【讨论】:

    • 感谢您的建议。试过了,可惜没用!
    • @BenToscano 你能发布 self.imageviews 如何初始化的代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 2019-05-26
    相关资源
    最近更新 更多