Keller
Keller

Reputation: 17081

Loading a random UIViewController?

I would like to pick a random UIViewController from a stored list of view controllers to load after one has finished. Yes, it needs to be a UIViewController and not just a UIView. I'm thinking I could do this with a .plist, but how would I go from the string name of a view controller to the actual view controller object name?

Upvotes: 2

Views: 770

Answers (1)

Eric Petroelje
Eric Petroelje

Reputation: 60518

To create an instance of a class from a name, you can use:

UIViewController* object = (UIViewController*)[[NSClassFromString(@"NameofClass") alloc] init];

Upvotes: 12

Related Questions