有没有办法可以通过使用String在objective-c中创建/创建一个类,就像我可以在AS3中使用getDefinitionByName一样?
Try:
id object = [[NSClassFromString(@"NameofClass") alloc] init];
from this thread:
I think you're looking for NSClassFromString. It should be used as such (I borrowed this code from this answer ; the code is from Dave DeLong):
Class dictionaryClass = NSClassFromString(@"NSMutableDictionary");
id object = [[dictionaryClass alloc] init];
[object setObject:@"Foo" forKey:@"Bar"];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.