gpt4 book ai didi

iphone - 使用 AccessToken 从 TabBarViewController 注销到 UIViewController

转载 作者:太空狗 更新时间:2023-10-30 03:54:51 26 4
gpt4 key购买 nike

我遇到了如何从“TabBarViewController”注销到“UIViewController”的问题。首先,我从 UIViewController 页面登录(使用 SOAP Web 服务 + XML 解析),如果用户 ID 和密码正确,则在数据库中生成“访问 token ”(在我们的页面中使用 XML 解析收集到变量中)并加载 TabBarViewController (用户个人资料页面)。现在登录后我想“注销”。在个人资料页面上,我放置了一个名为“注销”的按钮。

现在在这里,我需要你的帮助如何使用“访问 token ”(在成功登录期间生成)注销,以便我回到登录页面 agian ?????

下面是当我在 UITextField 中输入“用户 ID”和“密码”后按“登录”按钮时运行的代码:

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

//调用网络服务方法

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

//用于启动 TabBarViewController 的“showtabbar”方法

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

这是我的个人资料页面的“注销”方法,我想在其中编写用于从个人资料页面注销到登录页面(UIViewController)的代码

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

friend ,请回复。您的帮助将不胜感激。谢谢,陶西夫汗

最佳答案

不使用 [mainWindow addSubview],而是使用 mainWindow.rootViewController = tabbarcontroller;

这样,当按下注销按钮时,你只需要添加这样的东西:

mainWindow.rootViewController = loginViewController;

使用它,您只需更改显示在主窗口上的 View Controller ,并且您可以在新登录后以相同的方式再次切换到标签栏 Controller 。

关于iphone - 使用 AccessToken 从 TabBarViewController 注销到 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11216554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com