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 に答える