gpt4 book ai didi

objective-c - 应用程序不呈现模态视图 Controller

转载 作者:搜寻专家 更新时间:2023-10-30 19:41:45 25 4
gpt4 key购买 nike

我有一个 View Controller ,我想在加载 View 时从我的 Root View Controller 中呈现它。

我已将呈现 View Controller 设置为呈现 View 的委托(delegate)。

我有一个 UIBarbutton,当我点击时,使用与 viewDidLoad 完全相同的方法可以毫无问题地呈现 View ,在 viewDidLoad 方法我尝试呈现 View :

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

它不工作。

尝试在 viewDidLoad 方法中呈现 View 是否有问题?

整个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];

}

最佳答案

你不能从 viewDidLoad 中展示你的 View Controller ,尤其是 animated。那时你可能还在创建 subview ,所以 View 甚至还没有被渲染。

相反,您应该尝试在 viewDidAppear 中显示模态视图 Controller 。

关于objective-c - 应用程序不呈现模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13977690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com