简体   繁体   中英

iOS - Log UI events like a view controller appears/disappears

BugFender has a feature called UI Logging . What it does, for example, is monitors when a view controller comes onscreen and logs the information. Another example is when a button is touched:

Fri Aug 25 2017 08:24:30 GMT+0200 (CEST) UI Front-most view controller: SettingsViewController (title: "Settings")
Fri Aug 25 2017 08:24:35 GMT+0200 (CEST) Interaction Action [UIBarButtonItem _sendAction:withEvent:] by sender UINavigationButton (title:"Log Out")
Fri Aug 25 2017 08:24:35 GMT+0200 (CEST) Interaction Action [SettingsViewController logOut:] by sender UIBarButtonItem (title:"Log Out")
Fri Aug 25 2017 08:24:36 GMT+0200 (CEST) UI Front-most view controller: UIAlertController

I would like to implement have the same functionality.

How do I observe all view controllers in my app for appearance/disappearance?

So far, I have found out, I could observe UINavigationControllerDidShowViewControllerNotification notifications. However, this won't log changes in UITabBarViewController, or when a view controller is presented modally without being wrapped in a UINavigationController.

One of the ways is to add a base class (let's say BaseViewController) and override the base class's viewWillAppear and viewWillDisappear methods to observe the changes. All your other viewControllers would be subclasses of this BaseViewController.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM