I am wanting to use NSClassFromString() to pass a string to so that will be determining what class is pushed onto the nav controller. Problem is, I am wanting to pass a value to this class, which causes an error, as well as trying to push the view controller causes an error since NSObject is not a UIViewController type class.
Class screenClass = NSClassFromString(screen.name);
NSObject* newClass = [[screenClass alloc] init];
newClass.asset = asset; // Causes errors because asset not in NSObject
[self.navigationController pushViewController:newClass animated:YES];// newClass is an NSObject
[newClass release];
Is there a better way to do what I am trying here?
You can’t use dot notation if you can’t statically type the variable. If all all of the possible classes descend from one common class that declares the method, you can statically type it as that class. Otherwise, you’ll need to use the accessor method for the
assetproperty:This assumes that the setter for the
assetproperty issetAsset:(which it normally will be).