2012-12-20 75 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中展示您的模态视图控制器。

相关问题