开发者

Obj-C Macro programming

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜