我有两个视图控制器(view1 和 view2(say))。在 view1 中,我有用于输入用户名和密码的文本字段,以及一个登录按钮。按下登录后,用户应该能够推送到 view2(如果用户名和密码已从数据库中验证)。我添加了以下方法,单击登录时会调用该方法:
-(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 打印在日志中。我也应该在这里提到 view1 和 view2 具有相同的自定义类。(我正在使用情节提要)
好的,将它添加到 else 部分使其工作:
VIewControllerName *obj = [storyboard instantiateViewControllerWithIdentifier:@"ViewController_storyBoardId"];
[self.navigationController pushViewController:obj animated:YES];
感谢库马尔.. :)