我创建登录页面包括(用户名和密码和登录按钮)
如果正确的用户和密码进入另一页,我想何时填写文本字段用户名和密码,如果错误,请给我一个警报。
这是我的代码:
#import "Detail.h"
@implementation ViewController
{
NSString *name;
}
@synthesize Username,Password;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)Login:(id)sender {
NSString *a = [[NSString alloc]initWithFormat:@"http://192.168.1.102/mamal/login.php?u=%@&p=%@",Username.text,Password.text];
NSString *url = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:a]];
NSLog(@"%@",url);
if ([url isEqualToString:@"0"]) //this is wrong user & password
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ERROR" message:@"WRONG" delegate:nil cancelButtonTitle:@"Dissmis" otherButtonTitles: nil];
[alert show];
}
else
{
name = @"Mohammad";
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([name isEqualToString:@"Mohammad"] , [[segue identifier] isEqualToString:@"Segue"]) {
Detail *det = segue.destinationViewController;
}
}
但是工作!我只需要正确的用户名和密码进入下一页