我有一個簡單的問題。這是我的頭文件:存儲UIImageViews在NSMutableDictionary
#import <UIKit/UIKit.h>
@interface FirstFaceController : UIViewController
@property (nonatomic,retain) NSMutableDictionary *face1Layers;
@end
這.M,在這裏我初始化我的字典,並把其中的UIImageView:
#import "FirstFaceController.h"
@implementation FirstFaceController
@synthesize face1Layers;
-(void) dealloc {
[face1Layers release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.face1Layers = [NSMutableDictionary dictionary];
[self.face1Layers setObject:
[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic.png"]]
forKey:@"pic"];
[self.view addSubview:[self.face1Layers objectForKey:@"pic"]];
if ([[face1Layers objectForKey:@"pic"] superview] == nil) {
//....
}
}
然後我打電話[[face1Layers objectForKey:@"pic"]
上海華]我有 「EXC_BAD_ACCESS」。 爲什麼?
試試這個... self.face1Layers = [[NSMutableDictionary alloc] init]; – 2012-01-12 13:20:27
你是如何創建'self.view'的? – vikingosegundo 2012-01-12 13:29:08
我不太確定你想用if語句來檢查。如果你調用'[self.view addSubview:[self.face1Layers objectForKey:@「pic」]];'然後'[self.face1Layers objectForKey:@「pic」]'將始終有一個超級視圖,除非'self.view'確實不存在。 – FelixLam 2012-01-12 13:33:49