如何在ios中在前台输入时获取上一个视图

如何在ios中在前台输入时获取上一个视图,ios,Ios,我有一个聊天视图,我正在和某人聊天,当我在后台输入,再次在前台输入所有消息都已删除(刷新),我如何才能得到相同的聊天消息 - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the change

我有一个聊天视图,我正在和某人聊天,当我在后台输入,再次在前台输入所有消息都已删除(刷新),我如何才能得到相同的聊天消息

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    application.applicationIconBadgeNumber = 0;
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    SPHViewController *chatView = [[SPHViewController alloc] initWithNibName:@"SPHViewController" bundle:nil];
    chatView.strCallerName = [NSString stringWithFormat:@"%@",strSelectedCallerName];
    self.window.rootViewController = chatView;
    [self.window makeKeyAndVisible];
}

每次应用程序进入前台时,基本上都会重置应用程序状态。这不是实例化视图控制器和设置应用程序主窗口的地方。您需要在您的
应用程序IDFinishLaunching:

中执行此操作。我已经完成了此过程。。应用程序打开后,您需要重新填充chatView。如何重新填充chat view..@AhmedZ。您是否使用任何存储来保存消息?我使用核心数据来存储发送或接收消息时使用的发送方(即u)和接收方id,并将根据这些id组合重新填充。我只使用了ViewController