2012-03-08 43 views
0

到目前爲止,我已經通過在我的第一個視圖控制器中使用viewDidAppear中的方法獲得了我的登錄視圖以顯示在應用程序的開始位置,但是一旦Web服務批准了用戶名和密碼,第一個視圖控制器就會出現並且立即返回到登錄視圖。如何關閉我的登錄視圖以取得好效果?

我忘記了什麼?我只在我的登錄視圖和我的第一視圖編碼。

編碼爲第1:

- (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]; 

} 

繼承人的編碼在我loginview

- (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; 

    } 
} 

和我使用的是標籤欄模板

回答

1

通過調用:

- (void)viewDidAppear:(BOOL)animated 

你是p每當您的父視圖控制器進入視圖時,都會對loginView產生反感。我認爲實際發生的事情是,當登錄視圖被取消時,「viewDidAppear」會再次觸發登錄視圖。

嘗試把內部的邏輯 - (無效)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; 

} 
+0

謝謝你,我做通過使用布爾值來工作。 – loon3y 2012-03-12 21:35:11

相關問題