ios - 自动将屏幕内容保存到数据库

标签 ios iphone objective-c sqlite

我正在开发一个 iPAD 应用程序,我想每隔 10 秒将表单的内容自动保存到 SQLITE 中。现在,如果我按下保存按钮,它就会保存到数据库中。有什么方法可以每隔 10-15 秒自动保存我在表格中写的任何内容。帮我解决这个问题。

最佳答案

使用 NSTimer 并每 x 分钟执行一次保存。代码看起来像这样。它是代码的修改版本 here .

@interface MyController : UIViewController
{
  @private
  NSTimer * countdownTimer;
  NSUInteger remainingTicks;
}

-(IBAction)doCountdown: (id)sender;

-(void)handleTimerTick;

-(void) saveData;

@end

@implementation MyController

// { your own lifecycle code here.... }

-(IBAction)doCountdown: (id)sender
{
  if (countdownTimer)
    return;


  remainingTicks = 60;
  [self saveData];

  countdownTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(handleTimerTick) userInfo: nil repeats: YES];
}

-(void)handleTimerTick
{
  remainingTicks--;
  [self updateLabel];

  if (remainingTicks <= 0) {
    [countdownTimer invalidate];
    countdownTimer = nil;
  }
}

-(void) saveData
{
  //Save your data here
}


@end

关于ios - 自动将屏幕内容保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21757456/

相关文章:

iphone - 如何使用 NSXMLParser 正确设置我的对象?

iphone - 使用 NSPredicate 对多个实体执行查找

ios - 尝试在设备上运行我的应用程序时,找不到此可执行文件的有效配置文件

iphone - CLLocationManager distanceFilter 会做些什么来节省电量吗?

objective-c - 如何从 JSON 中解析 base64 图像

ios - 找不到与 Applications/***.app 匹配的配置文件

ios - NSLayoutconstraints 未按预期工作

iphone - AVAssetExportSession 在 iPhone 3G 上失败 - 但在 iPhone 4 上没有

ios - 知道在 AppDelegate 中选择了哪个 UITabBarItem

iphone - NSString 重音编码显示疯狂的字符