Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 自定义登录视图弹出窗口,如alertview_Iphone_Objective C_Ios_Uiviewcontroller_Uialertview - Fatal编程技术网

Iphone 自定义登录视图弹出窗口,如alertview

Iphone 自定义登录视图弹出窗口,如alertview,iphone,objective-c,ios,uiviewcontroller,uialertview,Iphone,Objective C,Ios,Uiviewcontroller,Uialertview,我试图使一个自定义登录视图弹出像一个警报视图。我用以下功能模拟alertview弹出窗口。此函数可在mine loginViewController.m中的viewDidload中找到 -(void)initialDelayEnded { self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001); self.view.alpha = 1.0; [UIView

我试图使一个自定义登录视图弹出像一个警报视图。我用以下功能模拟alertview弹出窗口。此函数可在mine loginViewController.m中的viewDidload中找到

-(void)initialDelayEnded {
    self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
    self.view.alpha = 1.0;
    [UIView animateWithDuration:1.0/1.5 animations:^{
        self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
    }completion:^(BOOL complete){
        [UIView animateWithDuration:1.0/2 animations:^{
            self.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
        }completion:^(BOOL complete){
            [UIView animateWithDuration:1.0/2 animations:^{
                self.view.transform = CGAffineTransformIdentity;
            }];
        }];
    }];
}
- (void)viewDidLoad
{
    [self initialDelayEnded];
    [super viewDidLoad];
}
我用以下方式调用我的firstViewController我的loginViewController

LoginViewController *login = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:NULL];
        [self presentViewController:login animated:YES completion:NULL];
但是它崩溃了,出现了以下错误

'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View <UIView: 0x8674bf0; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x8670620>> is associated with <LoginViewController: 0x868a7d0>. Clear this association before associating this view with <LoginViewController: 0x8451e70>.
“UIViewControllerHierarchyConsistency”,原因:“一个视图一次最多只能与一个视图控制器关联!视图与关联。在将此视图与关联之前,请清除此关联。
有人能帮我吗

提前谢谢

这里:

[self presentViewController:login animated:YES completion:NULL];
您自己演示了一个
viewController
,我猜它本身就是一个
viewController

相反,您应该使用:

[self presentModalViewController:login animated:YES];
如果要显示
viewcontroller
,而不是将其推到导航堆栈上。 在哪个类中使用此代码

这里:

[self presentViewController:login animated:YES completion:NULL];
您自己演示了一个
viewController
,我猜它本身就是一个
viewController

相反,您应该使用:

[self presentModalViewController:login animated:YES];
如果要显示
viewcontroller
,而不是将其推到导航堆栈上。
在哪个类中使用此代码

您是否检查了登录查看控制器xib?您是否有可能在同一视图中映射多个视图控制器?

是否检查了LoginViewController xib?是否有可能在同一视图中映射多个视图控制器?

除非有特殊原因,否则请保留
[super viewDidLoad]在本地实现中尽早完成调用。含义:调用
[self initialDelayEnded]
[super viewDidLoad]之后


请确保名为
LoginViewController
的.xib文件在
占位符
中只有一个
文件的所有者
,在
对象
面板中没有ViewController对象。并确保
文件的所有者
的自定义类是
LoginViewController
。请上传.xib的截图,特别显示
文档大纲
?如果你没有特殊的原因,就更容易判断出可能的错误,请保留
[super viewDidLoad]在本地实现中尽早完成调用。含义:调用
[self initialDelayEnded]
[super viewDidLoad]之后


请确保名为
LoginViewController
的.xib文件在
占位符
中只有一个
文件的所有者
,在
对象
面板中没有ViewController对象。并确保
文件的所有者
的自定义类是
LoginViewController
。请上传.xib的截图,特别显示
文档大纲
?更容易找出可能出现的错误

错误消息意味着“LogInViewController”有两个实例。你在用故事板吗?如果是这样,您可以将视图控制器添加到主故事板文件(而不是单独的nib),为其提供一个标记/标识符(但不要将其连接到其他VCs)。然后,您可以抓取故事板创建的实例并呈现该实例。像这样:

//Get the stroyboard
UIStoryBoard *mainStoryBoard = [UIStoryBoard storyboardWithName:<STORYBOARD_NAME> bundle:nil];

//Get the VC
LogInViewController *login = [mainStoryBoard instantiateViewControllerWithIdentifier:<VIEWCONTROLLER_TAG>];

//Present
[self presentModalViewController:login animated:YES];
//获取stroyboard
UIStoryBoard*MainstryBoard=[UIStoryBoard情节提要,名称:bundle:nil];
//获得VC
LogInViewController*login=[MainstryBoard实例化EVEWCONTROLLER标识符:];
//出席
[self-presentModalViewController:登录动画:是];

此外,您不应尝试在
viewdiload:
中显示其他视图控制器,否则将无法工作。移动代码以将新控制器显示到视图显示:

错误消息表示存在两个“LogInViewController”实例。你在用故事板吗?如果是这样,您可以将视图控制器添加到主故事板文件(而不是单独的nib),为其提供一个标记/标识符(但不要将其连接到其他VCs)。然后,您可以抓取故事板创建的实例并呈现该实例。像这样:

//Get the stroyboard
UIStoryBoard *mainStoryBoard = [UIStoryBoard storyboardWithName:<STORYBOARD_NAME> bundle:nil];

//Get the VC
LogInViewController *login = [mainStoryBoard instantiateViewControllerWithIdentifier:<VIEWCONTROLLER_TAG>];

//Present
[self presentModalViewController:login animated:YES];
//获取stroyboard
UIStoryBoard*MainstryBoard=[UIStoryBoard情节提要,名称:bundle:nil];
//获得VC
LogInViewController*login=[MainstryBoard实例化EVEWCONTROLLER标识符:];
//出席
[self-presentModalViewController:登录动画:是];

此外,您不应尝试在
viewdiload:
中显示其他视图控制器,否则将无法工作。移动代码以将新控制器显示到
视图显示:

我用以下方法解决了我的应用程序登录问题>

  • 已使用警报视图显示在ApplicationIDBecMeactive上的AppDelegate中
  • 将带有XIB的UIView控制器添加到名为LoginSubView的项目中。保持空白并添加标签,如99
  • 在警报框显示之前加载LoginSubView控制器

    AFLoginViewController *LoginSubView = [[AFLoginViewController alloc] init];
    [_window addSubview:LoginSubView.view];
    [_window makeKeyAndVisible];
    
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"This is an example alert!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Login", nil];
    alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
    [alert show];
    
  • 如果登录成功,我会先删除LoginSubView,然后再删除下面几行

    for (UIView *subView in _window.subviews)
    {
        if (subView.tag == 99)
        {
            [subView removeFromSuperview];
        }
    }
    
  • 也可以在ApplicationIdentinterBackground上添加相同的子视图。避免下次回到前台时敏感屏幕视图闪烁


  • 我通过以下方式解决了我的应用程序登录问题>

  • 已使用警报视图显示在ApplicationIDBecMeactive上的AppDelegate中
  • 将带有XIB的UIView控制器添加到名为LoginSubView的项目中。保持空白并添加标签,如99
  • 在警报框显示之前加载LoginSubView控制器

    AFLoginViewController *LoginSubView = [[AFLoginViewController alloc] init];
    [_window addSubview:LoginSubView.view];
    [_window makeKeyAndVisible];
    
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"This is an example alert!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Login", nil];
    alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
    [alert show];
    
  • 如果登录成功,我会先删除LoginSubView,然后再删除下面几行

    for (UIView *subView in _window.subviews)
    {
        if (subView.tag == 99)
        {
            [subView removeFromSuperview];
        }
    }
    
  • 也可以在ApplicationIdentinterBackground上添加相同的子视图。避免下次回到前台时敏感屏幕视图闪烁


  • 可能
    [super viewDidLoad]
    应该先去吗?没有仍然得到相同的错误