Pass a class as a parameter?
It looks like you've almost got it. You want to pass [RootViewController class]
instead of RootViewController
. That gives you a Class
value. Also, I don't think you want your function to take a Class *
, just a Class
. It's not actually an Objective-C object.
- (id)navControllerFromView:(Class)viewControllerClass
It's just Class
, without the asterisk. (Class
isn't a class name; you're not passing a pointer to an instance of the Class
class, you're passing the class itself.)
rootNavController = [ self navControllerFromView:RootViewController
You can't pass a bare class name around like this—you have to send it a message. If you actually want to pass the class somewhere, you need to send it the class
message. Thus:
rootNavController = [self navControllerFromView:[RootViewController class]
title:@"Contact"
imageName:@"my_info.png"
];