Ich habe gehört, dass viewDidLoad()
Methode mehrmals während der Ausführung des Codes aufgerufen wird..so wenn ich alloc
einige Ansichten in dieser Methode, Es wird eine neue pointer
jedes Mal erstellen, wenn es aufgerufen wird, ohne sie zu veröffentlichen.Abfragen über ViewDidLoad
hier ist meine Methode
-(void)viewDidLoad()
[b1 release];
[b2 release];
[b3 release];
[b4 release];
[b5 release];
[b6 release];
[b7 release];
[s1 release];
[s2 release];
[s3 release];
[s4 release];
[s5 release];
[s6 release];
[s7 release];
[bg release];
[bgview release];
[player release];
window = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 1026, 768)];
[window setImage:[UIImage imageNamed:@"backgrd99.png"]];
[self.view addSubview:window];
tree1 = [[UIImageView alloc]initWithFrame:CGRectMake(860,100,258,543)];
[tree1 setImage:[UIImage imageNamed:@"moving trees1.png"]];
[self.view addSubview:tree1];
//[tree1 release];
/*tree2 = [[UIImageView alloc]initWithFrame:CGRectMake(860,200,327,521)];
[tree2 setImage:[UIImage imageNamed:@"moving trees00010001.png"]];
[self.view addSubview:tree2];
[tree2 release];*/
bg = [[UIImageView alloc]initWithFrame:CGRectMake(-1,-1, 1026, 768)];
[bg setImage:[UIImage imageNamed:@"room99.png"]];
[self.view addSubview:bg];
bgsofa =[[UIImageView alloc]initWithFrame:CGRectMake(-1,-1
, 1026, 768)];
[self.view addSubview:bgsofa];
bgview = [[UIView alloc]initWithFrame:CGRectMake(230, 358, 80, 68)];
//[bgview setBackgroundColor:[UIColor cyanColor]];
[self.view addSubview:bgview];
bgview1 = [[UIView alloc]initWithFrame:CGRectMake(500,100, 500,200)];
//[bg setBackgroundColor:[UIColor greenColor]];
[self.view addSubview:bgview1];
sofapattelview =[[UIView alloc]initWithFrame:CGRectMake(530, 20, 440, 97)];
[sofapattelview setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:sofapattelview];
sofapattelimg =[[UIImageView alloc]initWithFrame:CGRectMake(0,0, 440, 97)];
[sofapattelimg setImage:[UIImage imageNamed:@"sofa-button1.png"]];
[sofapattelview addSubview:sofapattelimg];
// create the view that will execute our animation
/*colorbt =[UIButton buttonWithType:UIButtonTypeRoundedRect ];
colorbt.frame = CGRectMake(50, 50, 100, 50);
[colorbt setTitle:@"Paint" forState:UIControlStateNormal];
[colorbt addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:colorbt];*/
pattel = [[UIView alloc]initWithFrame:CGRectMake(58, 20, 440, 97)];
[pattel setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:pattel];
pattelimg =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 440, 97)];
[pattelimg setImage:[UIImage imageNamed:@"paint-button.png"]];
[pattel addSubview:pattelimg];
b1 =[[UIButton alloc] initWithFrame:CGRectMake(15, 33, 53, 51)];
[b1 addTarget:self action:@selector(B1) forControlEvents:UIControlEventTouchUpInside];
//[b1 setBackgroundColor:[UIColor cyanColor]];
[pattel addSubview:b1];
b2 =[[UIButton alloc] initWithFrame:CGRectMake(75, 33, 53, 51)];
[b2 addTarget:self action:@selector(B2) forControlEvents:UIControlEventTouchUpInside];
//[b2 setBackgroundColor:[UIColor cyanColor]];
[pattel addSubview:b2];
b3 =[[UIButton alloc] initWithFrame:CGRectMake(137, 33, 53, 51)];
[b3 addTarget:self action:@selector(B3) forControlEvents:UIControlEventTouchUpInside];
//[b3 setBackgroundColor:[UIColor cyanColor]];
[pattel addSubview:b3];
b4 =[[UIButton alloc] initWithFrame:CGRectMake(196, 33, 53, 51)];
[b4 addTarget:self action:@selector(B4) forControlEvents:UIControlEventTouchUpInside];
//[b4 setBackgroundColor:[UIColor cyanColor]];
[pattel addSubview:b4];
b5 =[[UIButton alloc] initWithFrame:CGRectMake(257, 33, 53, 51)];
[b5 addTarget:self action:@selector(B5) forControlEvents:UIControlEventTouchUpInside];
//[b5 setBackgroundColor:[UIColor cyanColor]];
[pattel addSubview:b5];
b6 =[[UIButton alloc] initWithFrame:CGRectMake(318, 33, 53, 51)];
[b6 addTarget:self action:@selector(B6) forControlEvents:UIControlEventTouchUpInside];
//[b6 setBackgroundColor:[UIColor cyanColor]];
[pattel addSubview:b6];
b7 =[[UIButton alloc] initWithFrame:CGRectMake(377, 33, 53, 51)];
[b7 addTarget:self action:@selector(B7) forControlEvents:UIControlEventTouchUpInside];
//[b7 setBackgroundColor:[UIColor cyanColor]];
[pattel addSubview:b7];
s1 =[[UIButton alloc] initWithFrame:CGRectMake(15, 33, 53, 51)];
[s1 addTarget:self action:@selector(S1) forControlEvents:UIControlEventTouchUpInside];
//[s1 setBackgroundColor:[UIColor blackColor]];
[sofapattelview addSubview:s1];
s2 =[[UIButton alloc] initWithFrame:CGRectMake(75, 33, 53, 51)];
[s2 addTarget:self action:@selector(S2) forControlEvents:UIControlEventTouchUpInside];
//[s2 setBackgroundColor:[UIColor blackColor]];
[sofapattelview addSubview:s2];
s3 =[[UIButton alloc] initWithFrame:CGRectMake(137, 33, 53, 51)];
[s3 addTarget:self action:@selector(S3) forControlEvents:UIControlEventTouchUpInside];
//[s3 setBackgroundColor:[UIColor blackColor]];
[sofapattelview addSubview:s3];
s4 =[[UIButton alloc] initWithFrame:CGRectMake(196, 33, 53, 51)];
[s4 addTarget:self action:@selector(S4) forControlEvents:UIControlEventTouchUpInside];
//[s4 setBackgroundColor:[UIColor blackColor]];
[sofapattelview addSubview:s4];
s5 =[[UIButton alloc] initWithFrame:CGRectMake(257, 33, 53, 51)];
[s5 addTarget:self action:@selector(S5) forControlEvents:UIControlEventTouchUpInside];
//[s5 setBackgroundColor:[UIColor blackColor]];
[sofapattelview addSubview:s5];
s6 =[[UIButton alloc] initWithFrame:CGRectMake(318, 33, 53, 51)];
[s6 addTarget:self action:@selector(S6) forControlEvents:UIControlEventTouchUpInside];
//[s6 setBackgroundColor:[UIColor blackColor]];
[sofapattelview addSubview:s6];
s7 =[[UIButton alloc] initWithFrame:CGRectMake(377, 33, 53, 51)];
[s7 addTarget:self action:@selector(S7) forControlEvents:UIControlEventTouchUpInside];
//[s7 setBackgroundColor:[UIColor blackColor]];
[sofapattelview addSubview:s7];
FileURL = [[NSURL alloc]initFileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Sunny" ofType:@"aac"]];
player = [[AVAudioPlayer alloc]initWithContentsOfURL:FileURL error:nil];
//[changecolor setAlpha:0.0];
[campFireView setAlpha:0.1];
[bgview setAlpha:1];
[self.view addSubview:toolbar];
}
meine App noch stürzen auch nach jedem Zeiger i alloc
kümmert ??
jus will wissen, ob dieser Ansatz richtig ist oder nicht ??
Ihre Syntax ist für eine objective-c-Methode deaktiviert :) Es sollte '- (void) viewDidLoad' sein; nicht '- (void) viewDidLoad()'; das wäre eine Mischung aus C und Obj-C, die es nicht gibt. –