私は簡単な質問があります。NSMutableDictionaryにUIImageViewsを保存
#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) {
//....
}
}
その後、私は "EXC_BAD_ACCESS" を持っている] [[face1Layers objectForKey:@"pic"]
スーパーを呼び出す:私は私の辞書を初期化し、UIImageViewをどこに置くここで、
#import <UIKit/UIKit.h>
@interface FirstFaceController : UIViewController
@property (nonatomic,retain) NSMutableDictionary *face1Layers;
@end
この.M:これは私のヘッダファイルです。 なぜですか?
これを試してください... self.face1Layers = [[NSMutableDictionary alloc] init]; –
'self.view'をどうやって作りましたか? – vikingosegundo
if文で何を確認しようとしているのかよくわかりません。 'self.view addSubview:[self.face1Layers objectForKey:@" pic "]];' then '[self.face1Layers objectForKey:@" pic "]'は 'self.view'がしなければ常にスーパービューを持ちます存在しない。 – FelixLam