How to retrieve value from database of SQLite onto UILabel but not in UITableView of UIView in iPhone?
If I want to show on UITableView this code is working fine but if I change one line of code to show the value on UILabel which is in UIView the project is crashes.
The code is here, please check it.
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.
}
@Samina when you display it on tableview it works fine and you are saying that you NSLog it shows null value so how you display it on tableview cell and can you post the Base class code