有没有什么办法让结果:如何获取没有实例的Class对象?
NSObject *a = [[NSObject alloc] init];
[a class];
没有实例? 我希望通过类对象作为参数,然后检查它。就像这样:
- (void) pushControllerOfClass: (Class) aClass
{
if([aClass isSubclassOfClass: *what should I write here?*]) {
...
}
}
直观地说,我试着写
if([aClass isSubclassOfClass: UIViewController]) {
但它不工作。 Thx未来响应。
更新: 在ObjectiveC中这样的功能被认为是不好的吗? 我从Nahavandipoor的书iOS 5编程手册重构的代码。 这就像:
- (void) pushSecondController{
SecondViewController *secondController = [[SecondViewController alloc]
initWithNibName:nil
bundle:NULL];
[self.navigationController pushViewController:secondController animated:YES];
}
对我来说,这是一种不好的功能: 当它应该是它不参数化。
您也可以编写'UIViewController.class'。 –