我正在开发联系人数据库应用程序。用户可以在 UITextFields 中输入姓名、电话、电子邮件,并将数据保存到 SQLite 数据库中。一切都按预期工作,但我想在数据成功保存时向用户显示确认信息。当记录保存到数据库时,实现了一个显示“已保存”的状态标签,但我希望文本在一秒钟后消失。
希望您能提供帮助,我尝试在 self.statusLabel.text = @"Saved";
之后立即执行 sleep()
函数,但没有成功。使用下面的代码
我看到状态标签显示“已保存”,但这应该会在一秒钟后自动消失。
- (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);
}
}
最佳答案
尝试使用
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
否则,您可以考虑实现一个 NSTimer
,它会在一秒钟后触发并清理标签。
关于iphone - UILabel > 显示文本(记录已保存)一秒钟然后清除 UILabel 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9956579/