In iOS development, to implement a jump between Uiviewcontroller, by Navigationcontroller Pushviewcontroller or Uiviewcontroller own Presentviewcontroller way. But the requirement is to jump from one uiviewcontroller to another uiviewcontroller. What if you want to jump to Uiviewcontroller from the execution code of the NSObject subclass?
First, explain why there is such a need, namely: Uicollectionview, Nsobjectsubclass, Uiviewcontroller:
Set Uicollectionview's DataSource and delegate to a nsobject subclass that handles all Uicollectionview and datasource related logical relationships with delegate. Then there may be a usage scenario in the execution code of this class that reverses to another uiviewcontroller. At this point, you cannot use pushviewcontroller because self has no Navigationcontroller property at all, and you cannot use Presentviewcontroller. Self is not a subclass of Uiviewcontroller.
The solution can be considered in two ways:
The way of delegate
Delegate is a very common approach in iOS. Set Uicollectionview xxxdelegate as the Nsobjectsubclass, implement the method XxxDelegateMethod1, The XxxDelegateMethod1 method of Xxxdelegate is then called in the execution code of the Nsobjectsubclass. The implementation of this method is in Uicollectionview (contains the Navigationcontroller property), so a normal jump between uiviewcontroller can be implemented.
Rootviewcontroller
In the execution code of Nsobjectsubclass, first get the current rootviewcontroller, jump between doing Uiviewcontroller:
UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];[rootViewController presentViewController:filterCourseViewController animated:NO completion:nil];
Finally, to achieve a jump between Uiviewcontroller, the Pushviewcontroller or Presentviewcontroller execution code in the class self must have a Navigationcontroller attribute, Or it must be a subclass of Uiviewcontroller.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS---Implement Uiviewcontroller jumps in the execution code of the NSObject subclass