2012-06-22 32 views
0

我試圖將爲Mac OS X編寫的一些代碼轉換爲iOS應用程序。這是OS X的工作代碼:如何轉換此NSImage代碼以供在iOS上使用

// 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; 

}

回答

0

就像猜測一樣,我認爲關鍵是self.imageviews。我猜你沒有初始化它。某處你應該有類似self.imageviews = [[NSMutableArray alloc] init];的東西。

+0

感謝您的建議。嘗試過,但不幸的是,不幸的是! –

+0

@BenToscano你可以發佈如何self.imageviews初始化的代碼? –

+0

剛剛編輯成問題:) –

相關問題