用户使用XCode登录ios
我有两个视图控制器(view1和view2(说))。在视图1中,我有用于输入用户名和密码的文本框以及登录按钮。在按下登录时,用户应该能够推送到view2(如果用户名和密码是从数据库验证的)。我已经添加下面的方法,当点击登录时被调用:用户使用XCode登录ios
-(IBAction)clickButton:(id)sender
{ const char *dbpath = [mDatabasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &mDiary) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat: @"SELECT *FROM USERDETAIL"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(mDiary,
query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
Gusr = [[NSString alloc]
initWithUTF8String:
(const char *) sqlite3_column_text(statement, 0)];
Gpass = [[NSString alloc]
initWithUTF8String:
(const char *) sqlite3_column_text(statement, 1)];
NSLog(@"%@ %@",Gusr,Gpass);
NSLog(@"%@ %@",mUserName.text,mPassword.text);
if (!([mUserName.text isEqualToString:Gusr] && [mPassword.text isEqualToString:Gpass])){
NSLog(@"Invalid credentials");
mUserName.text = @"";
mPassword.text = @"";
// [self performSegueWithIdentifier:@"Login" sender:self];
}else {
}
}
}
sqlite3_finalize(statement);
}
sqlite3_close(mDiary);
}
的问题是,用户能够与任何凭据登录。 Gusr和Gpass正在登录日志。我也应该可能求佛这里厂景和视图2具有相同的自定义类(我用故事板)
确定加入这else部分也可以正常工作。
VIewControllerName *obj = [storyboard instantiateViewControllerWithIdentifier:@"ViewController_storyBoardId"];
[self.navigationController pushViewController:obj animated:YES];
由于库马尔.. :)
尝试这样的:
if ([mUserName.text isEqualToString:Gusr] && [mPassword.text isEqualToString:Gpass]){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
VIewControllerName *obj = [storyboard instantiateViewControllerWithIdentifier:@"ViewController_storyBoardId"];
[self.navigationController pushViewController:obj animated:YES]; // This is using by navigation controller , Are You using it?
}else {
NSLog(@"Invalid credentials");
mUserName.text = @"";
mPassword.text = @"";
}
谢谢..我试过这个,但是抛出了下面的异常:在Bundle NSBundle Users/Guest/Library/Application Support/iPhone Simulator/6.0/Applications/CCEB4AAE-A6D6中找不到一个名为'MainStoryboard_iPhone.storyboard'的故事板-4C2E-A13D-BCF2695D2786/SmartDiary.app>(已加载)'我从故事板中删除了push segue,然后它对无效凭据正常工作。当证书正确时,这个异常显而易见。 – 2013-05-01 13:08:36
对不起,延期..不要放在扩展名。 .just把“MainStoryboard_iPhone” – 2013-05-01 15:07:13
谢谢.. :)我已经以不同的方式编辑它,但它的工作..请告诉我,如果这是适当的 – 2013-05-01 15:34:37
打印的用户名和密码也进行检查。 – Balu 2013-05-01 12:06:17
感谢您的回复。我已经做到了。而且两者都正在印刷。 – 2013-05-01 12:21:27
不是Gusr,Gpass打印mUserName.text,mPassword.text值。 – Balu 2013-05-01 12:23:12