2012-12-20 79 views
4

我有一個視圖控制器,我想從我的根視圖控制器呈現視圖加載時。應用程序不呈現模態視圖控制器

我已將呈現視圖控制器設置爲呈現視圖的代表。

我有一個UIBarbutton,當我點擊,視圖被使用做同樣的事情作爲viewDidLoad的方法,在viewDidLoad方法我努力表現的觀點帶有沒有問題:

modalViewController.delegate = self; 
modalViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:modalViewController animated:YES]; 

它不起作用。

試圖在viewDidLoad方法中呈現視圖是否存在問題?

整個viewDidLoad方法:

- (void)viewDidLoad { 
[super viewDidLoad]; 

UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
navigationBar.tintColor = [UIColor blackColor]; 
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithTitle:@"    " 
                    style:UIBarButtonItemStyleDone 
                   target:self 
                   action:@selector(changePlayersNames)];//Check how to highlight the button 
//Label for UIBarButton text 
UILabel *barButtonLabel = [[UILabel alloc] initWithFrame:CGRectMake(3, 5, 70, 30)]; 
barButtonLabel.text = @"Players"; 
[barButtonLabel setFont:[UIFont fontWithName:@"ChalkboardSE-Bold" size:15.0]]; 
barButtonLabel.textAlignment = UITextAlignmentCenter; 
barButtonLabel.backgroundColor = [UIColor clearColor]; 
barButtonLabel.textColor = [UIColor whiteColor]; 

//Set UINavigation item 
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@""]; 
item.leftBarButtonItem = leftBarButton; 
item.hidesBackButton = YES; 
[navigationBar pushNavigationItem:item animated:YES]; 

//Label for the navigation title 
UILabel *barTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 160, 30)]; 
barTitleLabel.center = navigationBar.center; 
barTitleLabel.text = @"Tic-Tac-Toe"; 
[barTitleLabel setFont:[UIFont fontWithName:@"ChalkboardSE-Bold" size:20.0]]; 
barTitleLabel.textAlignment = UITextAlignmentCenter; 
barTitleLabel.backgroundColor = [UIColor clearColor]; 
barTitleLabel.textColor = [UIColor whiteColor]; 
[self.view setBackgroundColor:[UIColor whiteColor]]; 

[self.view addSubview:navigationBar]; 
[self.view addSubview:barTitleLabel]; 
[self.view addSubview:barButtonLabel]; 

self.player1 = [[ORDPlayer alloc] init]; 
self.player2 = [[ORDPlayer alloc] init]; 

[self setNamesLabels:@"Player 1" :@"Player 2"]; 


//TapRecognizer 
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] 
            initWithTarget:self action:@selector(tapRecognized:)]; 
singleTap.numberOfTapsRequired = 1; 
singleTap.numberOfTouchesRequired = 1; 
singleTap.delegate = self; 
[self.view addGestureRecognizer:singleTap]; 

//Present modal view 
self.playerChangeController = [[ORDPlayerChangeController alloc] 
           initWithNibName:@"ORDPlayerChangeController" bundle:nil]; 
playerChangeController.delegate = self; 
playerChangeController.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
[self presentModalViewController:playerChangeController animated:YES]; 

} 
+0

順便說一句,你設置過渡樣式爲另一個vc – Shmidt

+0

viewDidLoad方法應該做的工作好。你有沒有其他的viewDidLoad?如果是這樣,也許發佈整個方法。你在哪裏/如何分配/初始化modalViewController? – foundry

回答

4

您不能從viewDidLoad出示您的視圖控制器,尤其不能animated。那時你可能還在創建子視圖,所以視圖甚至沒有渲染。

相反,您應該嘗試在viewDidAppear中展示您的模態視圖控制器。

相關問題