Как извлечь значение из базы данных SQLite на UILabel, но не в UITableView UIView на iPhone?
Если я хочу показать на UITableView, этот код работает нормально, но если я изменяюодна строка кода, показывающая значение UILabel, которое находится в UIView, в проекте происходит сбой.
Код здесь, пожалуйста, проверьте его.
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
Base *baseObjects = [[Base alloc] init];
[Base getInitialDataToDisplay:[self getDBPath]];
label1 = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, 350, 65)];
label1.backgroundColor = [UIColor grayColor];
label1.text = baseObjects.tLabel; //String to Retrieve but crash
label1.font = [UIFont fontWithName:@"Arial-BoldMT" size:30.0];
label1.text =@"";
label1.textColor = [UIColor blackColor];
label1.textAlignment = UITextAlignmentCenter;
[self.view addSubview:label1];
}
+ (void) getInitialDataToDisplay:(NSString *)dbPath {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "select formId, tLabel,Fname,Mname from addEdit";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
[appDelegate.baseArray removeAllObjects];
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
Base *baseObjects = [[Base alloc] initWithPrimaryKey:primaryKey];
baseObjects.tLabel = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
baseObjects.Fname= [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
baseObjects.isDirty = NO;
[appDelegate.baseArray addObject:baseObjects];
[baseObjects release];
}
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}