2013-02-13 88 views
0

我有一个提交按钮的用户登录页面,成功登录后我想转到下一个视图。为此,我打电话给web服务(这将验证来自后端数据库的数据)这将取决于成功或失败返回true或false.This工作正常;也就是说,我能得到使用的NSXMLParser值如下:根据SOAP消息值显示下一个视图

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 
    if (elementFound) { 
     soapResults = [string boolValue]; 
     //NSLog(@"soapResultss = %@",soapResults); 

    } 
    if (soapResults) 
    { 
     x = 1; // x is 1 if username and password are correct. 
    } 
    else 
    { 
     x = 0;//x is 0 if username and password are incorrect 
    } 
} 

平均值,而(成功),我想这样调用下一个视图在我的“提交键”的方法:

if(x==0) 
    { 

    } 
    else if(x==1) 
    { 
     [self.navigationController pushViewController:self.viewController animated:YES]; 
    } 

但问题是,控制不回到“提交按钮单击”,即“其他如果”部分。而且,我认为这不是正确的方法。什么是正确的如何做到这一点?请建议。谢谢。

+0

请澄清一下 “控制不回来了这种” 手段。 – trojanfoe 2013-02-13 12:38:49

+0

更新了我的问题。 – bapi 2013-02-13 12:46:01

+0

您需要在推送的视图控制器中创建自定义委托协议,并将原始视图控制器作为委托对象。这被用于在弹出时将状态返回到原始视图控制器。请参阅:http://stackoverflow.com/questions/11632043/use-of-delegates-to-communicate-between-view-controllers – trojanfoe 2013-02-13 12:50:16

回答

0

您检查这行代码,为什么你使用的是自与视图控制器对象

[self.navigationController pushViewController:self.viewController animated:YES]; 

使用这行代码(你的ViewController的对象)

[self.navigationController pushViewController:viewController animated:YES]; 
-1

好看起来好像只是使用TRUE/FALSE不会在这种情况下工作..

试图enum数据类型将生效

在.h文件中

enum { 
    kReceivingSoapData, 
    kReceivedIncorrectData, 
    kReceivedCorrectData 

}receivedSoapResult; 

@interface ViewController : UIViewController{ 
..... 
} 

的方法中使用

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 
    if (elementFound) { 
     soapResults = [string boolValue]; 
     //NSLog(@"soapResultss = %@",soapResults); 

    } 
    if (soapResults) 
    { 
    receivedSoapResult = kReceivedCorrectData; 
    } 
    else 
    { 
     receivedSoapResult = kReceivedIncorrectData;; 
    } 
} 

的操作方法

if(receivedSoapResult == kReceivedIncorrectData) 
    { 
// incorrect uName and password received 
    } 
    else if(receivedSoapResult == kReceivedCorrectData) 
    { 
     //correct password received 
     [self.navigationController pushViewController:self.viewController animated:YES]; 
    } 
else{ 
// still receiving data 

} 
+0

这个'enum'如何改进'BOOL';无论如何,你只能使用2个值。 – trojanfoe 2013-02-13 13:17:29

+0

如果(x == 0)在这里创建了两个条件,首先如果响应尚未接收或接收到的响应为FALSE,则使用前一个条件来处理是否使用枚举。 – AppleDelegate 2013-02-13 13:23:58

+0

您不会显示将'receivedSoapResult'初始化为'kReceivingSoapData',因此它不是显而易见的。你甚至不解决正确的问题;他的问题是视图控制器“不回来提交按钮点击”。 – trojanfoe 2013-02-13 13:26:24