S Sergio10 macrumors regular Original poster Oct 3, 2007 137 0 Jan 18, 2010 #1 Hi, Here is a code: PHP: NSString* className = @"SomeClass" UIViewController *viewController = [[(Class)className alloc] initWithNibName:aXIBName bundle:[NSBundle mainBundle]]; It crashes. How to solve the problem? Thank you.
Hi, Here is a code: PHP: NSString* className = @"SomeClass" UIViewController *viewController = [[(Class)className alloc] initWithNibName:aXIBName bundle:[NSBundle mainBundle]]; It crashes. How to solve the problem? Thank you.
robbieduncan Moderator emeritus Jul 24, 2002 25,611 893 Harrogate Jan 18, 2010 #2 Use NSClassFromString to turn your string into a Class then you can alloc init as usual: Code: NSString* className = @"SomeClass" id myInstance = [[NSClassFromString(className) alloc] init];
Use NSClassFromString to turn your string into a Class then you can alloc init as usual: Code: NSString* className = @"SomeClass" id myInstance = [[NSClassFromString(className) alloc] init];