2013-01-09 98 views
-3

我不想在用戶按Home按鈕時關閉我的應用程序。取而代之,我需要返回到重新打開應用程序後離開的相同頁面。主頁按鈕事件

+0

你能解釋一下嗎? –

+2

如果你正在談論iPhone的家庭按鈕,那麼它不可能,如果你正在談論你的應用程序主頁按鈕,然後請解釋更多關於你的問題。 –

+0

我正在談論iphone主頁按鈕。 – karthi

回答

1

如果你正在使用其他視圖控制器,而不是使用此功能關閉按鈕。

對於舊版本:

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

對於iOS6的:

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

它會自動將您重定向到從那裏導航到當前視圖控制器視圖控制器。

0

我認爲你正試圖保存應用程序的狀態,當它進入背景,然後檢索它時,它涉及到前景。嘗試閱讀約NSUserDefaults。這裏是文檔link

+0

感謝您的回答。 – karthi

+0

@karthi您可以通過[此鏈接](http://stackoverflow.com/questions/1811696/how-to-preserve-iphone-application-state-before-terminating-the-application?answertab=active#tab-頂部)也有點類似的其他堆棧溢出問題。它可能只有幫助 – Zen

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鍵。你的應用程序不會停止。它在後臺進行。您可以在這些函數中編寫邏輯,以確保您的應用程序在停止的同一個類中打開。

0

iPhone/iPad主頁按鈕始終關閉當前應用程序並返回到主屏幕。這種行爲不能被應用程序覆蓋。

0

我假設你正在談論物理主頁按鈕。 Apple沙盒除了自己的應用程序之外的所有應用程序,因此您無法訪問iDevices的某些方面,包括所有硬件按鈕。如果你想申請回當用戶離開其進入後臺後,您可以使用該方法在委託文件,即

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

如果您的問題涉及只是在返回給用戶一個離開的地方不同類型的感覺(以及物理主頁按鈕)...

就像Zen說的那樣,如果你想要填充某個文本字段(比如說下一次用戶去填充它)出。即

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]];