我正在 XCode 中为 iOS 应用程序创建登录页面。屏幕上有一个登录按钮,以及用户名和密码文本字段。单击按钮后,应执行用户身份验证,并且用户应该能够进入下一个屏幕。我正在使用以下代码:
-(IBAction)validateLogin:(id)sender
{ Gusr = @"";
Gpass = @"";
const char *dbpath = [mDatabasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &mDiary) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:
@"SELECT mPassword FROM USERDETAIL WHERE mUserName=\"%@\"",
mUserName.text];
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);
// NSLog(@"'%@'",Gpass);
if ([mUserName.text isEqualToString:Gusr] && [Gpass isEqualToString:mPassword.text]){
[self performSegueWithIdentifier:@"Login" sender:self];
}else {
NSLog(@"not valid");
}
sqlite3_finalize(statement);
}
sqlite3_close(mDiary);
}
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"Login"]) {
// Get destination view
dashboardViewController *vc = [segue destinationViewController];
// Get button tag
NSInteger tagIndex = [(UIButton *)sender tag];
// Set the selected button in the new view
// [vc setSelectedButton:tagIndex];
}
}
在运行构建时,我收到以下异常:由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:' * -[NSPlaceholderString initWithUTF8String:]: NULL cString'
究竟是什么问题?即使异常已修复,此代码是否可以成功执行登录?