我正在检查WebAPI userId
和userPWD
的用户凭据并检查它们。如果用户有效,那么他访问该应用程序。如果没有,那么我向用户显示AlertView
控制器,他不是有效的用户。怎么做。 请给我一个例子。如何比较Objective-C中的两个字符串
我在这里发布我的代码:
为其这里if([jstr isEqualToString:@"Invalide Login Credential."])
{
UIAlertController *alert=
[UIAlertController alertControllerWithTitle:@"Enter valid Details." message:@"invalid" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok =
[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];
NSLog(@"Invalide Login Credential.");
//Invalide Login Credential.
}
响应:
Jstr = Invalide Login Credential.
你可以显示你的json解析,否则添加一些额外的代码 –
我认为这是错的jstr –
代码是正确的,使用isEqualToString来比较两个字符串。 如果不起作用,请在代码的第一行插入断点(或NSLog)并检查jstr值。 – Kerberos