2011-11-04 113 views

回答

4

實施代碼,如answer中的示例。讓您的視圖控制器註冊UIApplicationWillResignActiveNotification。通知觸發時,請致電resignFirstResponder。這樣可以避免UIApplicationDelegate與視圖控制器之間的緊密耦合。假設您的視圖控制器具有UITextField名爲textField

- (void) applicationWillResign { 
    [self.textField resignFirstResponder]; 
} 

- (void) viewDidLoad { 
    [[NSNotificationCenter defaultCenter] 
     addObserver:self 
     selector:@selector(applicationWillResign) 
     name:UIApplicationWillResignActiveNotification 
     object:NULL]; 
} 
+0

那麼我怎麼能逆轉applicationWillResign做出改變?一旦短信關閉,我該如何重新打開鍵盤? –

+0

[self.textField becomeFirstResponder] – jluckyiv

+0

是的,但該陳述去哪裏? –