I am working on a contacts database App. User can enter name, phone, email in UITextFields and save data to a SQLite database. All works as expected but I like to show the user a confirmation when data was successfully saved. Implemented a status label showing “Saved” when record was saved to DB but I like the text to disappear after a second.
Hope you can help, I tried to implement the sleep() function right after self.statusLabel.text = @"Saved"; but it did not work. With code below
I get the status label to say “Saved” but this should disappear automatically after a second.
- (IBAction)saveButtonTapped:(id)sender
{
sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &timings) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO TIMINGS (time) VALUES (\"%@\")", self.timeLabel.text];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(timings, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
self.statusLabel.text = @"Saved";
self.timeLabel.text = @"0:00:00";
}
else
{
self.statusLabel.text = @"Failed";
}
sqlite3_finalize(statement);
sqlite3_close(timings);
}
}
Try using
Otherwise you may consider implement a
NSTimerthat fires after a second and clean the label.