gpt4 book ai didi

objective-c - 为什么我不能关闭我加载的 View Controller ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:34 24 4
gpt4 key购买 nike

我使用单击按钮时触发的 IBAction 成功加载了一个新的 View Controller 。

-(IBAction)changeToAnotherView:(id)sender 
{
if (self.newController == nil)
{
newController = [[UIViewController alloc] initWithNibName:@"NewViewController" bundle:[NSBundle mainBundle]];
}
quizController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:newController animated:YES completion:NULL];
}

但是,我在 NewViewController.m 中返回旧 View 的函数没有构建。为什么?

- (IBAction)goBackToOldView:(id)sender
{
[self dismissWithClickedButtonIndex:0 animated:YES];
}

我得到的构建错误是“没有可见的接口(interface)声明 dismissWithClickedButtonIndex:animated:”。


更新:

lldb 现在输出

"2012-04-30 21:31:56.530 Project32[10105:fb03] -[UIViewController goBackToOldView:]: unrecognized selector sent to instance 0x6c57f20
2012-04-30 21:31:56.531 Project32[10105:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController goBackToOldView:]: unrecognized selector sent to instance 0x6c57f20'
*** First throw call stack:
(0x1649052 0x1bfdd0a 0x164aced 0x15aff00 0x15afce2 0x164aec9 0x2d05c2 0x50bd54 0x164aec9 0x2d05c2 0x2d055a 0x375b76 0x37603f 0x3752fe 0x2f5a30 0x2f5c56 0x2dc384 0x2cfaa9 0x2536fa9 0x161d1c5 0x1582022 0x158090a 0x157fdb4 0x157fccb 0x2535879 0x253593e 0x2cda9b 0x217d 0x20e5)
terminate called throwing an exception(lldb)"

有趣的是,我在 NewViewController 中实现了 goBackToOldView:

- (IBAction)goBackToOldView:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}

最佳答案

因为这不是正确的函数,所以它应该是。

[self dismissViewControllerAnimated:YES completion:Nil];

(您可以在完成时将 nil 替换为 block 以在 Controller 被解雇后执行某些操作。)

关于objective-c - 为什么我不能关闭我加载的 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10392284/

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