我正嘗試在工廠模型樣式中創建具有多個圖像的模型。我有一個類處理個人,一個類處理個人和一個ViewController。Objective-C:類之間的圖像管理
testImage = [[UIImageView alloc] initWithFrame:CGRectMake(250, 500, 30, 30)];
testImage.image = [UIImage imageNamed:@"myImage.png"];
testImage.animationDuration = 1.5;
testImage.contentMode = UIViewContentModeCenter;
[self.view addSubview:testImage];
http://jcdeveloperworld.blogspot.com/2009/07/iphone-game-tutorial-part-1.html - 感謝
該代碼工作時,它只是在的viewController,現在我試圖使個人跟蹤自己的形象的。所以我把
testImage = [[UIImageView alloc] initWithFrame:CGRectMake(250, 500, 30, 30)];
testImage.image = [UIImage imageNamed:@"myImage.png"];
testImage.animationDuration = 1.5;
testImage.contentMode = UIViewContentModeCenter;
[self.view addSubview:testImage];
在一個單獨的類,然後試圖從我的viewController顯示它。這是我的理解,我不能告訴viewController顯示一個單獨的類的東西。
flock *newFlock = [[flock alloc] init];
[newFlock makeFlock];
NSMutableArray *tempFlock = [[NSMutableArray alloc] init];
tempFlock = newFlock.theFlock;
individualsClass *tempIndividual = [[individualsClass alloc] init];
tempIndividual = [tempFlock objectAtIndex:0];
UIImageView *tempImage = [[UIImageView alloc] initWithFrame:CGRectMake(250, 500, 30, 30)];
tempImage = tempIndividual.individualImage;
[self.view addSubview:tempImage];
我也試了一下沒有所有的複製,但點符號開始得到的方式,因爲我在訪問一個NSMutableArray對象的屬性(這似乎荒謬很難在客觀C)。我也可以用一些幫助來計算出這一點
即。
flock.[theFlock.individualImage.image objectAtIndex:1] //Doesn't work
我是一種新的客觀C,所以也許我攻擊這個問題是錯誤的。這是爲iPad應用程序完成的
我也想強調,重要的是要堅持命名約定,這意味着類名應始終以大寫字母開頭。使用ARC時,這些約定部分成爲強制執行的規則。但是,即使沒有ARC,在使用與其他人相同的約定時,也會讓您的生活以及其他人的代碼更加輕鬆。 – DarkDust