Created
October 7, 2017 09:08
-
-
Save kuju63/04563b5826343a2abd4a20676631b3a4 to your computer and use it in GitHub Desktop.
iOSアプリでフォアグラウンドに移行した際に画面を更新する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
@IBOutlet weak var viewLabel: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// NotificationCenterを使用して、フォアグラウンドに移った時に指定のメソッドを実行する | |
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.didForeground), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
func didForeground() { | |
// この画面が表示されている時のみ実行する | |
if (self.isViewLoaded && self.view.window != nil) { | |
print("foreground show") | |
viewLabel?.text = "foreground" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment