I'm trying to learn more about macro programming for Obj-C, as I have seen quite a bit of cool stuff done with it. Is it is possible to accomplish the following with a one-line macro?
MyNewViewController *newVC = [[MyNewViewController alloc] init];
[self.navigationController pushViewController:newVC animated:YES];
[newVC release];
Something like:
PushToNavController(@"MyNewViewController",YES);
开发者_高级运维
Thanks
Sure:
#define PushToNavController(_n,_a) { \
_n *__vc = [[(_n) alloc] init]; \
[self.navigationController pushViewController:__vc animated:(_a)]; \
[__vc release]; \
}
And then you'd use it like this:
PushToNavController(MyNewViewController, YES);
But.. why do you want to do this?
精彩评论