URL scheme is the basic navigationcontroller, which enables loose coupling between viewcontroller and independent
Use
Urlmanager provides two navigationcontrollers, one webviewcontroller and one basic viewcontroller, which can be used separately or in combination.
Umviewcontroller
The basic viewcontroller of urlmanager. To use urlmanager, you must use umviewcontroller instead of uiviewcontroller as the base class.
Umviewcontroller can use URL initialization (as follows ). But it is generally not used directly, but through the factory method of navigationcontroller.
- (id)initWithURL:(NSURL *)aUrl;- (id)initWithURL:(NSURL *)aUrl query:(NSDictionary *)query;
The following method is triggered when a new viewcontroller is opened through a URL:
-(Bool) shouldopenviewcontrollerwithurl :( nsurl *) aurl; // whether to enable-(void) openedfromviewcontrollerwithurl :( nsurl *) aurl; // Where
Umnavigator
Umnavigator is a singleton object. It can monitor the viewcontroller currently displayed and use the URL management mechanism to replace the push and pop mechanisms of uinavigationcontroller.
Relationship between registered URL and viewcontroller
[[UMNavigator sharedNavigator] setViewControllersForKeysFromDictionary:@{@"nava":navA, @"navb":navB}];
Or
[[UMNavigator sharedNavigator] setViewControllerName:@"UMDemoViewController" forURL:@"demo"];
Or
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewControllerURL: [[NSURL URLWithString:@"um://demo"] addParams:[NSDictionary dictionaryWithObjectsAndKeys: @"Demo1", @"title", nil]]]; [[UMNavigator sharedNavigator] setViewController:navC forURL:@"navc"];
Initialize umnavigationcontroller
UMNavigationController * umNav = [[UMNavigationController alloc] initWithRootViewControllerURL:[[NSURL URLWithString:@"um://demo"] addParams:[NSDictionary dictionaryWithObjectsAndKeys: @"Demo", @"title", nil]]];[self.window addSubView:umNav.view];
Open a new viewcontroller
// Replace [self. navigationcontroller pushviewcontroller: animated:]; [[umnavigator sharednavigator] Openurl: [nsurl urlwithstring: @ "um: // demo? Title = nextdemo & Param = value "];
Call Openurl: the following method is triggered.
The following method is triggered in the caller controller. If yes is returned, the push effect is executed.
- (BOOL)shouldOpenViewControllerWithURL:(NSURL *)aUrl;
In the called viewcontroller, the following method is triggered:
- (void)openedFromViewControllerWithURL:(NSURL *)aUrl;
Umslidenavigationcontroller
Navigation bar, similar to sliding the path bar.
UINavigationController * navA = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]]; UMNavigationController * navB = [[UMNavigationController alloc] initWithRootViewControllerURL:[NSURL urlWithString:@"um://demo"]]; self.navigator = [[UMDemoSlideNavViewController alloc] initWithItems:@[@[navA, navB], @[navA]]];
Two notifications will be sent when the slide on the sidebar is about to appear and disappears.
- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] postNotificationName:UMNotificationWillShow object:nil];}- (void)viewDidDisappear:(BOOL)animated{ [super viewDidDisappear:animated]; [[NSNotificationCenter defaultCenter] postNotificationName:UMNotificationHidden object:nil];}
Umwebviewcontroller
When viewcontroller is managed by URL, umwebviewcontroller is automatically called if an http url is generated, and webview is loaded.
Project Link: https://github.com/gaosboy/URLManager