このような別のクラスのメソッド内でメソッドを呼び出すと、問題に直面しています
-(IBAction)login:(id)sender
{
DBHelper *objdb = [[DBHelper alloc] init];
[objdb loginnow:textname.text andpassword:textpassword.text];
}
DBhelper.mファイルでこのメソッドを呼び出すこのボタンメソッドと、このメソッドの呼び出しに成功しました
-(void) loginnow:(NSString *) username andpassword:(NSString *) password
{
[self createEditableCopyOfDatabaseIfNeeded];
[self initializeDatabase];
const char *sql;
NSString *querySQL = [NSString stringWithFormat: @"SELECT username, password FROM CONTACT WHERE username='%@' AND password='%@'",username,password];
sql = [querySQL UTF8String];
if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
while (sqlite3_step(init_statement) == SQLITE_ROW)
{
NSLog(@"char sql = %s" ,sql);
dbusername = [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement,0)];
dbpassword = [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement,1)];
}
if ([dbusername isEqualToString:username] && [dbpassword isEqualToString:password])
{
//DBHelper.callingViewController = self;
[self.callingViewController addview];
}
else if (dbusername != username || dbpassword != password)
{
NSLog(@"dbusername is = %@" ,dbusername);
NSLog(@"dbpassword is = %@" ,dbpassword);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Login Failed"
message:@"Username Or Password is not Correct"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK ", nil];
[alert show];
[alert release];
}
sqlite3_reset(init_statement);
[self closeDatabase];
}
また、DBhelper.hiでこれのプロパティを定義します
@property (strong) ViewController * callingViewController;
パスワードとユーザー名が正常に一致する場合、lognowメソッドのif条件内で、Viewcontroller.comファイルでこのmathodを呼び出していますが、//ViewController.mを呼び出すことができません
-(無効) addview {
DBHelper *f = [[DBHelper alloc] init];
f.callingViewController = self;
newview.center = CGPointMake(1000, 1000);
}