2012-06-26 2 views
5

Sono di fronte a un problema relativo alla disconnessione da "TabBarViewController" a "UIViewController". Prima di collegarmi (utilizzando il servizio Web SOAP + analisi XML) dalla pagina UIViewController, Se userId e Password sono corretti, il 'token di accesso' viene generato nel database e (raccolto in variabile utilizzando l'analisi XML nella nostra pagina) e TabBarViewController è caricato (pagina del profilo utente). Ora dopo la registrazione voglio "LogOut". Nella pagina del profilo ho posizionato un pulsante chiamato "Logout".Disconnessione da TabBarViewController a UIViewController utilizzando AccessToken

Ora qui, ho bisogno del tuo aiuto su come utilizzare LogOut utilizzando il 'token di accesso' (che viene generato durante la registrazione di successo) In modo che torni indietro alla pagina di accesso in avanti ?????

Qui di seguito è il codice è in esecuzione quando si preme il pulsante "Login" dopo aver inserito "User ID" e "Password" in UITextField:

-(IBAction)Login{ 

    txtuser.text = @"test"; 
    txtpwd.text = @"test"; 

    if([txtuser.text isEqualToString:@"" ]|| [txtpwd.text isEqualToString:@""]) 
    { 
     UIAlertView *myAlert = [[UIAlertView alloc] 
           initWithTitle:nil message:@"Please fill all fields" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [myAlert show]; 
     [myAlert release]; 
    } 
    else 
    { 

    md5 =[txtpwd text]; 

    //Calling MD5 Method to Convert password into "hashcode"(Hexadecimal) formate 
    md5 = [md5 MD5]; 

    NSLog(@"%@",md5); 
    itmselected =FALSE; 

// metodo di chiamata Web Service

NSString *soapmessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
          "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" 
          "<soap:Body>\n" 
          "<Login xmlns=\"http://boleapp.com/\">\n" 
          "<UserName>%@</UserName>\n" 
          "<PassHash>%@</PassHash>\n" 
          "</Login>\n" 
          " </soap:Body>\n" 
          " </soap:Envelope>\n",[txtuser text],md5]; 
    NSLog(@"%@",soapmessage); 
    NSURL *url = [NSURL URLWithString:@"http://weibotest.dotnetgeekz.com/servicemain.asmx"]; 
    NSMutableURLRequest *req = [[NSMutableURLRequest alloc]initWithURL:url]; 

    NSString *msglength = [NSString stringWithFormat:@"%d",[soapmessage length]]; 
    [req addValue:@" text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [req addValue:@"http://boleapp.com/Login" forHTTPHeaderField:@"SOAPAction"]; 
    [req addValue:msglength forHTTPHeaderField:@"Content-Length"]; 
    [req setHTTPMethod:@"POST"]; 
    [req setHTTPBody:[soapmessage dataUsingEncoding:NSUTF8StringEncoding]]; 
    [NSURLConnection connectionWithRequest:req delegate:self]; 
    webadata = [[NSMutableData alloc]init]; 
    [txtuser resignFirstResponder]; 
    [txtpwd resignFirstResponder]; 
    } 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 
    [webadata appendData:data];  
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ 
    NSLog(@"error"); 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{ 
    xmlparser = [[NSXMLParser alloc]initWithData:webadata]; 
    [xmlparser setDelegate:self]; 
    [xmlparser parse]; 
} 

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ 


    if([elementName isEqualToString:@"Login"]) 

     soapresult = [[NSMutableString alloc]init]; 
    itmselected = YES; 

} 

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ 
    if(itmselected){ 
     NSLog(@"Bool value and Access Token Number and UserID= %@",string); 

     if([string isEqualToString:@"false"]){ 
      [invaliduser setImage:[UIImage imageNamed:@"invalid_username.png"]]; 

     } 
     else{ 
     NSArray* splits = [string componentsSeparatedByString: @","]; 
     NSString *strbool = [splits objectAtIndex:0]; 
     NSString *strAtoken = [splits objectAtIndex:1]; 
     id UserIdLogin = [splits objectAtIndex:2]; 
     if ([strbool isEqualToString:@"true"]){ 

      main.strAccessTokenMain = strAtoken; 
      main.UserIdMain = UserIdLogin; 
      NSLog(@"strAccessTokenMain = %@",[main strAccessTokenMain]); 

      // Calling "showtabbar" method for Loading TabBarViewController page 
      [main showtabbar];  
     } 
     } 
     [soapresult appendString:string]; 
    } 
} 

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ 

    if([elementName isEqualToString:@"LoginResult"]){ 
     itmselected = NO; 
    } 
} 

// Metodo "showtabbar" per il lancio di TabBarViewController

- (void) {showtabbar

//Removing UIViewController's 'Login' page 
[self.view removeFromSuperview]; 
[BoleApp release]; 

NSLog(@"userID = %@",UserIdMain); 
tabbarcontroller = [[UITabBarController alloc]init ]; 

//Creating Object of "Profile" Class for Launching as First tab of TabBarViewController 
profile *view1 = [[profile alloc]initWithNibName:@"profile" bundle:nil ]; 
view1.strAccessToken = strAccessTokenMain; 
view1.UserIdProfile = UserIdMain; 
NSLog(@"view1str = %@",view1.strAccessToken); 
view1.title = @"Profile"; 
view1.tabBarItem.image = [UIImage imageNamed:@"profile.png"]; 

//Second Tab of TabBarViewController 
Brandslist *view2 = [[Brandslist alloc]init]; 
view2.BrandAccToken = strAccessTokenMain; 
view2.UserIdBrndList = UserIdMain; 
Instruction *view3 = [[Instruction alloc]init]; 
settings *view4 = [[settings alloc]init]; 
view2.title = @"Brands"; 
view2.tabBarItem.image = [UIImage imageNamed:@"brands.png"]; 

// Third Tab of TabBarViewController 
view3.title = @"Info"; 
view3.tabBarItem.image = [UIImage imageNamed:@"info.png"]; 

// Fourth Tab of TabBarViewController 
view4.title = @"Settings"; 
view4.tabBarItem.image = [UIImage imageNamed:@"settings.png"]; 
view4.AccessToken = strAccessTokenMain; 
view4.user_ID = UserIdMain; 

[tabbarcontroller setViewControllers:[NSArray arrayWithObjects:view1,view2,view3,view4, nil]]; 

[mainWindow addSubview:tabbarcontroller.view]; 

}

Questa è la mia pagina profilo Method "Logout" dove voglio scrivere il codice per logout da pagina profilo alla pagina di login (UIViewController)

-(IBAction)Logout{ 
    NSLog(@"Logout Button Clicked !!!"); 
    // What to code here for resuming back to Login page ????? Please Help me out 
    ? 
    ? 
    ? 
} 

Amici, Si prega di ritornare di nuovo. Il tuo aiuto sarebbe apprezzato . Grazie, Tauseef Khan

risposta

1

Invece di usare, [mainWindow addSubview], utilizzare mainWindow.rootViewController = tabbarcontroller;

In questo modo, quando si preme il pulsante di logout, avete solo bisogno di aggiungere qualcosa di simile:

mainWindow.rootViewController = loginViewController; 

Usando questo, stai solo cambiando il viewcontroller visualizzato nella finestra principale, e puoi passare nuovamente al controller della barra delle schede nello stesso modo, dopo un nuovo login.

+0

questo non funziona per me !!! @paul N – NSExpression

+0

Devi rimuovere tutte le linee di codice [mainWindow addSubview: yourController.view] nella tua app e sostituirle con mainWindow.rootViewController = yourController. –

0

Sarebbe conveniente mostrare loginViewController come controller di visualizzazione modale. In questo modo è sempre possibile presentare il modale loginViewController se il server restituisce l'errore di autorizzazione.

+0

Puoi elaborarlo !! Non ho avuto quello che stai dicendo ... @onegray – NSExpression

+0

Penso che dopo che l'utente è stato disconnesso, deve mostrare di nuovo la schermata di login. Oppure l'utente può diventare non autorizzato in modo imprevisto, ad esempio se il token di autenticazione è scaduto. In questo modo potrebbe essere utile mostrare la schermata di accesso modale che si sovrappone alle altre schermate dell'app. – onegray

+0

Sì, stai pensando bene ... Ma io non so come far scadere il token di accesso nel mio caso ... se mi fornisci il codice per quello sarebbe fantastico per me ... Come ho già perso più di 4 ora per risolvere questo problema ... @onegray Aiutami ad aiutare gli altri – NSExpression