使用宏定义替代控制器跳转
1、导航push
宏定义
#define NAVPUSH(_VIEWCONTROLLER_) ({\ _VIEWCONTROLLER_ *(^block)(void) = ^{_VIEWCONTROLLER_ *controller = [[_VIEWCONTROLLER_ alloc]init];\ [self.navigationController pushViewController:controller animated:true];\ return controller;};\ LeJSZDViewController*controller = block();\ (controller);\ })\
使用方法触发push效果 方便调用一句话实现push 也可以穿参
NAVPUSH(LeJSZDViewController).name = @"极速指导"; //传参数
NAVPUSH(LeJSZDViewController)//也可以不穿参数
LeJSZDViewController *vc = NAVPUSH(LeJSZDViewController);//也可以获取对象
以前push是这样的
LeJSZDViewController *controller = [[LeJSZDViewController alloc]init];
controller.name = @"极速指导";
[self.navigationController pushViewController:controller animated:true];
使用宏之后是这样的
NAVPUSH(LeJSZDViewController);
如果要传参数(只有一个参数)
NAVPUSH(LeJSZDViewController).name = @"极速指导";
有多个参数
LeJSZDViewController * controller = NAVPUSH(LeJSZDViewController);
controller.name = @"极速指导";
controller.title = @"极速指导";
2.STORYBOARD便捷引用
#define NAVPUSHSTORYBOARD(_STORYBOARDVIEWCONTROLLER_,_NAME_,_INDENTIFER_) ({\
_STORYBOARDVIEWCONTROLLER_ *(^block)(void) = ^{_STORYBOARDVIEWCONTROLLER_ *controller = [[UIStoryboard storyboardWithName:_NAME_ bundle:nil] instantiateViewControllerWithIdentifier:_INDENTIFER_];\
[self.navigationController pushViewController:controller animated:true];\
return controller;};\
_STORYBOARDVIEWCONTROLLER_*controller = block();\
(controller);\
})\
3.模态
#define PRENT(_VIEWCONTROLLER_)({\
_VIEWCONTROLLER_ *(^block)(void) = ^{_VIEWCONTROLLER_ *controller = [[_VIEWCONTROLLER_ alloc]init];\
[self presentViewController:controller animated:true completion:nil];\
return controller;};\
_VIEWCONTROLLER_*controller = block();\
(controller);\
})\
2和3 使用方法和1 一样 个人觉得比较简单,分享!!!