IOS---Implement Uiviewcontroller jumps in the execution code of the NSObject subclass

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.