繁体   English   中英

目标C:后退按钮搜索无效

[英]Objective C: Back button segue not working

我有一个带有2个屏幕的简单应用程序。 当我按一个按钮从第一到第二时,一切都成功执行(包括动画)。 但是,当我单击第二个屏幕上的“后退”按钮时,收到以下警告:

Warning: Attempt to present <getTextViewController: 0x8f6aa30> on <SecondViewController: 0x946cc80> whose view is not in the window hierarchy!

编辑:请不要将我引介到其他有关上述警告的问题-我已经看到了,而他们指的是其他问题。

但是,它仍然切换回第一个屏幕。 但是,segue的动画无法执行。 另外:当我返回第一个屏幕时,第一个屏幕中的信息(例如输入的文本)仍然保留,而每次出现屏幕时,第二个屏幕中的信息都会重置。

这是我称之为两种操作的方式:

Segue from View 1 to View 2:
Name: F21, Style: Modal, Transition: Cross Dissolve, Animation: True.

Segue from View 2 to View 1:
Name: F12, Style: Modal, Transition: Cross Dissolve, Animation: True.

getTextViewController.m中的代码(视图1):

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"F21"]){
    UIViewController *v = [segue destinationViewController];
   [self dismissViewControllerAnimated:NO completion:nil];
    v = self;

}
}
-(void)performSegue:(NSString*)str{
[self performSegueWithIdentifier:str sender:self];
}
//In some other method:
[self performSegue:@"F21"];

SecondViewController.m中的代码(视图2):

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"F12"]){
    UIViewController *v = [segue destinationViewController];
    [self dismissViewControllerAnimated:NO completion:nil];
    v = self;

}
}
-(void)performSegue:(NSString*)str{
[self performSegueWithIdentifier:str sender:self];
}
- (IBAction)goBack:(id)sender {
[self performSegue:@"F12"];

}

我非常感谢您提供帮助,以帮助您理解为什么第一个序列有效而第二个序列却无效。

谢谢,

院长

注意:这是完整的项目-https: //github.com/dean13-meet/firstIOSApp编辑:更新了git。

我不能完全确定您要在prepareForSegue尝试做什么,他们不需要解雇那里的VC。 如果要使用一个简单的应用程序,从VC1转到VC2,然后再返回,那么最好的选择是使用segueunwindSegue

因此,在情节提要控件中,从VC1上的按钮拖动到VC2,然后选择您的segue类型。 然后在VC1.m中设置展开序列,例如:

 - (IBAction)unwindFromViewController:(UIStoryboardSegue *)segue
 {
    //empty implementation
 }

最后,在VC2控件中,从后退按钮拖动到VC2上的绿色退出图标,然后选择unwindFromViewController方法。

那应该做您想要的。

为了简单起见,我建议您使用与模式相反的推式按钮,因为它可以为您处理所有后退按钮。 但是,如果您不喜欢导航控制器的想法,请尝试使用以下方法消除视图: 从控制器移回到上一个视图

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM