-3

当用户按下主页按钮时,我不想关闭我的应用程序。相反,我需要在重新打开应用程序后返回到我离开的同一页面。

4

5 回答 5

1

如果您使用的是其他视图控制器,而不是将此功能用于关闭按钮。

对于旧版本:

-(IBAction)Close:(id)sender{
    [self dismissModalViewControllerAnimated:YES];
}

对于 iOS6:

-(IBAction)closebtn:(id)sender{
{
    [self dismissViewControllerAnimated:YES completion:Nil];
}

它会自动将您重定向到视图控制器,从它导航到当前视图控制器。

于 2013-01-09T06:42:38.000 回答
0

我假设您正在谈论物理主页按钮。Apple 将所有应用程序沙箱化,除了他们自己的应用程序,因此您无法访问 iDevices 的某些方面,包括所有硬件按钮。如果您希望应用程序在进入后台后返回用户离开的位置,您将使用委托文件中的方法,即

- (void)applicationDidEnterBackground:(UIApplication *)application {// your code}

如果您的问题仅涉及以不同的方式返回用户停止的位置(以及物理主页按钮)......

就像 Zen 说的那样,如果您想在下次用户填写某个文本字段时填写某个文本字段,您可以使用用户默认值。IE

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if (!defaults) {
    [self setDefaults]; // where setDefaults is just a method that set some random values
}

int apples = [[NSUserDefaults standardUserDefaults] integerForKey:@"apples"];
if (apples == 0) {
    apples = 2;
}

// fill in the interface values for xibApples, a UITextField outlet
[xibApples setText:[NSString stringWithFormat:@"%d", apples]];
于 2013-01-09T05:34:37.430 回答
0

我认为您正在尝试在应用程序进入后台时保存应用程序的状态,然后在前台进行检索。尝试阅读有关NSUserDefaults. 这是文档链接

于 2013-01-09T05:18:38.570 回答
0

这些是您的选择

在您的应用委托中:

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

当用户按下 Home 按钮时,这些方法会按特定顺序调用。您的应用程序不会停止。它在后台运行。您可以在这些函数中编写逻辑,以确保您的应用程序在它停止的同一个类中打开。

于 2013-01-09T05:19:42.643 回答
0

iPhone/iPad 主页按钮始终关闭当前应用程序并返回主屏幕。此行为不能被应用程序覆盖。

于 2013-01-09T05:24:35.230 回答