How to do some stuff in viewDidAppear only once?

前端 未结 8 1458
暖寄归人
暖寄归人 2020-11-29 03:25

I want to check the pasteboard and show an alert if it contains specific values when the view appears. I can place the code into viewDidLoad to ensure it\'s onl

8条回答
  •  情话喂你
    2020-11-29 04:07

    By reading other comments (and based on @rmaddy 's answer), I know this is not what OP asked for, but for those who come here because of title of the question:

    extension UIViewController {
        var isPresentingForFirstTime: Bool {
            return isBeingPresented() || isMovingToParentViewController()
        }
    }
    

    UPDATE

    You should use this method in viewDidAppear and viewWillAppear. (thanks to @rmaddy)

    UPDATE 2

    This method only works with modally presented view controllers and pushed view controllers. it's not working with a childViewController. using didMoveToParentViewController would be better with childViewControllers.

提交回复
热议问题