在 ModalViewController 中呈现 ModalViewController
我有一个视图,它显示为模态视图控制器,它接受用户名和密码凭据。我希望此视图检查委托,如果用户之前没有为应用程序设置解锁引脚,则将更改引脚视图显示为模式视图控制器。这是我的代码...
+(void)presentCredentialsViewController:(UIViewController *)vc{
CredentialsViewController *cvc = [[CredentialsViewController alloc] init];
[vc presentModalViewController:cvc animated:FALSE];
}
然后在 CredentialsViewController 中
-(void)viewDidLoad{
[super viewDidLoad];
if([appDelegate.pin isEqualToString: @""]){
UserPrefsViewController *upvc = [[UserPrefsViewController alloc] init];
upvc.cancelButton.hidden = true;
[self presentModalViewController:upvc animated:FALSE];
}
}
但由于某种原因它不起作用。调试器单步执行代码,不会出现错误,但第二个模式视图控制器不会显示。
I have a view which is presented as a modal view controller which takes username and password credentials. I want this view to check the delegate, and if the user hasn't previously set an unlock pin for the app, to then show the change pin view as a modal view controller. This is my code...
+(void)presentCredentialsViewController:(UIViewController *)vc{
CredentialsViewController *cvc = [[CredentialsViewController alloc] init];
[vc presentModalViewController:cvc animated:FALSE];
}
and then in CredentialsViewController
-(void)viewDidLoad{
[super viewDidLoad];
if([appDelegate.pin isEqualToString: @""]){
UserPrefsViewController *upvc = [[UserPrefsViewController alloc] init];
upvc.cancelButton.hidden = true;
[self presentModalViewController:upvc animated:FALSE];
}
}
But for some reason it doesn't work. The debugger steps through the code without error, never the less, the second modal view controller isn't displayed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我建议检查您的
appDelegate.pin
是否为空而不是 nil。如果它为零,则 if 语句将不被满足,并且您的第二个 ModalView 将不会呈现。您可能还想尝试之前的建议,从
viewDidAppear
调用presentModalViewController
,或者如果将其保留在viewDidLoad
中,则设置延迟。当 CredentialsViewController 尚未呈现时,它可能会尝试呈现第二个视图。First, I would suggest checking that your
appDelegate.pin
is blank and not nil. If it is nil, the if statement would not be satisfied and your second ModalView would not be presented.You may also want to try the previous suggestion, calling
presentModalViewController
fromviewDidAppear
, or setting a delay if leaving it inviewDidLoad
. It is possible that theCredentialsViewController
is trying to present the second view when it has not yet presented itself.if 语句被命中,第二个 PresentModalViewController 正在执行,没有错误,但它只是没有显示。我确实尝试将代码放入 ViewDidAppear 以及其他一些地方,例如 applicationWillBecomeActive 等。虽然实际上并没有使代码崩溃,但这些方法仍然不会显示视图控制器。最后我选择了这个:
有点黑客,但现在就可以了。我想我应该在某个地方放置某种通知,警告该引脚尚未设置。我想关于延迟的建议可能会奏效。我将来可能会尝试一下。谢谢各位……加分!
The if statement is being hit and the second PresentModalViewController is executing without error, but it just wasn't displaying. I did try putting the code in ViewDidAppear and a load of other places as well, such as applicationWillBecomeActive etc. Although not actually crashing the code, still none of these approaches would show the view controller. In the end I have opted for this:
Bit of a hack but it will do for now. I suppose I should put some sort of notification in somewhere warning that the pin hasn't been set. The suggestion about the delay may possibly work I suppose. I might give it a go in the future. Thanks guys....points up!