MYRoutes 0.1.0

MYRoutes 0.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

未声明的所有者 维护。



MYRoutes 0.1.0

  • masafumi yoshida

简化应用程序视图转换。原始 API 使其非常简单且更有用。

  • 简化代码。自动推送和显示到当前控制器的 viewcontroller
  • 支持 UINavigationController 转换完成。不使用代理
  • 支持带参数的转换
  • 支持类似网络服务的 URL 路由

用法

URL 路由

可以处理各种类型的 URL。类似于网络服务路由。

路由配置

 [[MYRoutes shared] loadRouteConfig:@[
      @[@"/nib/:message" , @{@"nib":@"XIBTestViewController",@"class":@"MYViewController"}],
      @[@"/storyboard/first/:message" , @{@"storyboard":@"Main",@"identifier":@"First"}],
 ]];

带有参数从 Xib 进行转换

// push MYViewController from Xib has message an categoryId parameters 
[routes dispatch:@"/nib/hello?category_id=1"]

带有参数从 Storyboard 进行转换

// push MYViewController from Storyboard has message parameter 
[routes dispatch:@"/storyboard/first/hello"]

从 URL 方案打开

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    // dispatch from url scheme. example xxxx://tweet/view/id
    return [[MYRoutes shared] dispatch:url ];
}

打开外部应用程序

[routes dispatch:@"http://www.yahoo.co.jp"]

手动转换

推送到 UINavigationController

推送视图控制器
// auto search current navigation contorller
[routes pushViewController:viewController animated:YES];
与 Storyboard
MYRoutes *routes = [MYRoutes shared];
[routes pushViewController:@"ViewControllerIdnetifier" withStoryboard:@"StoryboardName" animated:YES];
与 Xib
[routes pushViewController:@"ViewController" withNib:@"ViewControllerXIB" animated:YES];
扩展功能:使用导航完成块而不仅使用委托
[routes pushViewController:@"ViewControllerIdnetifier" withStoryboard:@"StoryboardName" animated:YES completion:^{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"navigation complete"
                                                    message:@"complete!!"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
[alertView show];

}];

显示视图控制器

推送视图控制器
// auto search current viewcontorller
[routes presentViewController:viewController animated:YES completion:nil];
与 Storyboard
[routes presentViewController:@"ViewControllerIdnetifier" withStoryboard:@"StoryboardName" animated:YES completion:nil];
与 Xib
[routes presentViewController:@"ViewController" withNib:@"XIBTestViewController" animated:YES completion:nil];
带参数的转换
NSDictionary *params = @{@"message":self.messageTexfield.text};
[routes presentViewController:@"ViewControllerIdnetifier" withStoryboard:@"StoryboardName" animated:YES completion:nil];
[routes pushViewController:@"ViewControllerIdnetifier" withStoryboard:@"StoryboardName" withParameters:params animated:YES completion:nil];