storyBoard 通过其进行界面跳转的封装类

来源:互联网 发布:java this的作用 编辑:程序博客网 时间:2024/06/09 15:35


首先写一个类别,用的时候直接调用类别的方法,下方是封装的类别的.h 和 .m文件:

.h文件

////  NSObject+PushNextControllerTool.h#import <Foundation/Foundation.h>@interface NSObject (PushNextControllerTool)/** *  通过UINavigationController进行界面的跳转 * *  @param control    自己的现在的界面的控制器 即self  传入self *  @param storyName  要跳转的界面所在的StoryBoard名字 *  @param identifier 要跳转的界面在storyBoard中的控制器的标识符 * *  @return nil */+(UIViewController *)PushWithSelfController:(UIViewController *)control NextViewControlerWithStorbordName:(NSString *)storyName withControllerIdentifier:(NSString *)identifier;@end

.m文件:

////  NSObject+PushNextControllerTool.m#import "NSObject+PushNextControllerTool.h"@implementation NSObject (PushNextControllerTool)+(UIViewController *)PushWithSelfController:(UIViewController *)selfController NextViewControlerWithStorbordName:(NSString *)storyName withControllerIdentifier:(NSString *)identifier{    UIStoryboard *MicroCourseLiveStoryBoard = [UIStoryboard storyboardWithName:storyName bundle:nil];    UIViewController *nextPageController  = [MicroCourseLiveStoryBoard instantiateViewControllerWithIdentifier:identifier];    selfController.hidesBottomBarWhenPushed = YES;    [selfController.navigationController pushViewController:nextPageController animated:YES];     return nextPageController;}@end


在控制器当中调用方法:

   GuestIntroduceViewController *CourseChoVC = [UIViewController PushWithSelfController:self NextViewControlerWithStorbordName:@"CourseLiveRoom" withControllerIdentifier:@"GuestIntroduceViewController"];


该方法返回的是下一个界面的控制器,所以可以通过该控制器进行传值等等。。。例如  CourseChoVC.name = @"ddd";  这样就可以吧下一个控制器所需要的name传递过去。


5 0
原创粉丝点击