我有一个视图控制器,我想在加载视图时从我的根视图控制器呈现。
我已将呈现视图控制器设置为呈现视图的委托。
我有一个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];
}