0

我有一个带有提交按钮的用户登录页面,成功登录后我想转到下一个视图。为此,我正在调用 Web 服务(这将验证来自后端数据库的数据),它将根据成功或失败返回 true 或 false .这工作正常;也就是说,我能够使用 NSXMLParser 获得价值,如下所示:

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

但是,问题是,控件没有回到“提交按钮单击”,即“else if”部分。而且,我认为这不是正确的做法。正确的做法是什么? 请建议。谢谢。

4

2 回答 2

0

你检查你这行代码为什么你用视图控制器对象使用self

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

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

 [self.navigationController pushViewController:viewController animated:YES];
于 2013-02-13T12:41:38.033 回答
-1

好的,在这种情况下,似乎只使用 TRUE/FALSE 不起作用..

尝试enumdataType 会有效

在 .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

}
于 2013-02-13T13:09:56.410 回答