我有一个带提交按钮的用户登录页面,在成功登录后我想转到下一个视图。为此,我调用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];
}
但是,问题是,控件没有回到"提交按钮点击",即"否则如果" part.And,我认为这不是正确的方法。这样做的正确方法是什么?请建议。谢谢。
答案 0 :(得分:0)
您检查这行代码为什么使用自身与视图控制器对象
[self.navigationController pushViewController:self.viewController animated:YES];
使用这行代码(ViewController的Object)
[self.navigationController pushViewController:viewController animated:YES];
答案 1 :(得分:-1)
好吧看起来好像只使用TRUE / FALSE在这种情况下不会工作..
尝试enum
dataType将有效
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
}