我在viewDidLoad()
以外的方法中添加子視圖,並且不顯示子視圖。 我的代碼是在這裏如下:在viewDidLoad以外的方法中添加子視圖
-(void) displayBanner
{
SharedApp *instance=[SharedApp sharedInstance];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats:YES];
numTimerTicks = 0;
roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect]retain]; //Creates a UIButton
roundedButtonType.frame = CGRectMake(0.0f, 360.0f, 320.0f, 60.0f); //sets the coordinates and dimensions of UIButton
roundedButtonType.backgroundColor = [UIColor clearColor]; //sets the background color
roundedButtonType.tag = numTimerTicks;
// [instance configView];
NSLog(@"the home array is %@",instance.homeImageArray);
[roundedButtonType setBackgroundImage:[instance.homeImageArray objectAtIndex:numTimerTicks] forState:UIControlStateNormal];
[roundedButtonType addTarget:self action:@selector(showDetails:)forControlEvents:UIControlEventTouchUpInside]; //sets the Background image
[roundedButtonType setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
HomePageViewController *homepage = [[HomePageViewController alloc]initWithNibName:@"HomePageViewController" bundle:nil];
[homepage.view addSubview:roundedButtonType];
//Oops forgot to add this one... my bad.. :D :D
[self.view addSubview:homepage.view];// Image displayed but goes into endless loop
}
任何人都可以讓我知道如果我已經做了正確的,什麼我已經錯過?
在此先感謝。
謝謝。我試過這樣。請讓我知道它是否正確。 'HomePageViewController * homepage = [[HomePageViewController alloc] initWithNibName:@「HomePageViewController」bundle:nil]; [self presentModalViewController:homepage animated:YES]; [homepage.view addSubview:roundedButtonType];' – user1268938