ios - 如何永久关闭我的登录 View ?

标签 ios authentication modalviewcontroller

到目前为止,我已经通过在第一个 View Controller 中使用 viewDidAppear 中的方法让登录 View 出现在应用程序的开头,但是一旦用户名和密码获得 Web 服务的批准,第一个 View Controller 出现一瞬间,然后立即返回登录 View 。

我是不是忘记了什么???我只在我的登录 View 和我的第一个 View 中进行编码。

第一次编码:

 - (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [vc setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:vc animated:YES];
    [self dismissModalViewControllerAnimated:YES];

}

这是我的登录 View 中的编码

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{ 
    NSMutableString *Yes =[[NSMutableString alloc] initWithString:@"Y"];

    if ([ capturedCharacters isEqualToString:Yes])
    {
            //[self presentModalViewController:vc animated:YES];

        [self dismissModalViewControllerAnimated:YES];  
    }
    else
    {
        // ask user to login again, 
    }

   [capturedCharacters release];
    capturedCharacters = nil;

    if ([elementName isEqualToString:@"str_partinfo"]) {
        // We are no longer in an item element
        inItemElement = NO;

    }
}

我正在使用标签栏模板

最佳答案

通过调用:

 - (void)viewDidAppear:(BOOL)animated

每次您的父 View Controller 进入 View 时,您都会呈现登录 View 。我认为实际发生的情况是,当登录 View 被关闭时,“viewDidAppear”会触发,再次调用登录 View 。

尝试将逻辑放入 -(void)viewDidLoad 中,看看是否有效:

  - (void)viewDidLoad
 {
     [super viewDidLoad];

     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
     UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
     [vc setModalPresentationStyle:UIModalPresentationFullScreen];

     [self presentModalViewController:vc animated:YES];
     [self dismissModalViewControllerAnimated:YES];

 } 

或者,您可以有一个 BOOL 指针,伪代码:

 BOOL loginSuccessful;
 if(!loginSuccessful)
 {
      //ShowLogin
      loginSuccessful = TRUE;

 }

关于ios - 如何永久关闭我的登录 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9626282/

相关文章:

ipad - 关闭模态视图 Controller 导致布局问题

ios - 无法创建供应配置文件 - 我在哪里可以免费捆绑标识符?

PHP 登录表单不会使用正确的凭据登录用户

authentication - cakephp 基于组的权限

python - 如何实现django otp?

ios - 从另一个模态视图呈现透明模态视图

iOS 7 模态视图转换和背景/墙纸

ios - UINavigationBar 色调颜色不更新

ios - 如何在 dealloc 方法中引用 __weak self

iphone - iOS - UITextView 不绘制文本?