Ios xCode分配问题,我想是的

Ios xCode分配问题,我想是的,ios,iphone,objective-c,xcode,postdata,Ios,Iphone,Objective C,Xcode,Postdata,我正在使用此代码将Post登录发送到一个页面: NSString *kode = Password.text; NSString *post = [NSString stringWithFormat:@"user=%@&pass=%@&login=login", bruger.text, kode]; NSData *postData= [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

我正在使用此代码将Post登录发送到一个页面:

NSString *kode = Password.text;
NSString *post = [NSString stringWithFormat:@"user=%@&pass=%@&login=login", bruger.text, kode];
NSData *postData= [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [NSMutableURLRequest new];
[request setURL:[NSURL URLWithString:@"http://itskp-odense.dk/portal.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *strdata=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

if ([strdata rangeOfString:@"Log ud"].location != NSNotFound){
    //Hvis koden/bruger var fokert gør dette:
    response = nil;
    strdata = nil;
    request = nil;
    AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.sharedString = bruger.text;
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"second"];
    [self presentViewController:vc animated:YES completion:nil];
}else{
    UIAlertView *fejl = [[UIAlertView alloc] initWithTitle:@"Fejl Opstået" message:@"Dit brugernavn eller kode var fokert" delegate:Nil cancelButtonTitle:@"Prøv igen" otherButtonTitles: nil];
    [fejl show];
}
然后使用以下代码段将我发送到另一个视图:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"second"];
[self presentViewController:vc animated:YES completion:nil];
我检查strdata是否包含字符串,如果包含,则登录成功并切换视图。然后我做了一个简单的注销按钮,将视图切换回主视图,即登录。现在,如果我在文本字段中输入随机数据,它仍然允许我切换视图

让我试着用另一种方式来解释这一点。 上面的代码允许我将post数据发送到web页面,并检查响应中的字符串,以确定此人输入的信息是否正确,以及登录是否成功。然后,如果找到字符串,它会将视图切换到表视图

然后在表视图中我创建了一个注销按钮,它所做的只是一个到主视图的模式分段。如果我输入随机数据,在不关闭应用程序的情况下,它仍然会将视图切换到表视图,即使信息不正确。无论我在字段中键入什么,它都会将我发送到下一个视图,它不应该这样做,因为它是不正确的信息,它不明白为什么会这样做


提前谢谢。

尝试打印您的响应如果我没有错,您只检查字符串中的“注销”,而不检查其他内容。因此,无论通过什么程序,您都不会按下“注销”按钮。因此,您将登录。所以,检查你是否检查了正确的东西。