根据类名创建ViewController

来源:互联网 发布:票据市场知乎 编辑:程序博客网 时间:2024/06/05 10:58


NSString * className = [NSString stringWithFormat:@"%@ViewController", _dataSource[indexPath.row]]; //创建视图控制器的Class //使用class间接使用类名,即使不加头文件,也能创建对象。 //编译器要求直接引用类名等标识符,必须拥有声明。 Class aVCClass = NSClassFromString(className); //创建vc对象 UIViewController * vc = [[aVCClass alloc] init]; [vc performSelector:@selector(setDatArray:) withObject:[_resultData objectForKey:_dataSource[indexPath.row]]]; [vc performSelector:@selector(setTitle:) withObject:_dataSource[indexPath.row]]; NSString * className = [NSString stringWithFormat:@"%@ViewController", _dataSource[indexPath.row]]; //创建视图控制器的Class //使用class间接使用类名,即使不加头文件,也能创建对象。 //编译器要求直接引用类名等标识符,必须拥有声明。 Class aVCClass = NSClassFromString(className); //创建vc对象 UIViewController * vc = [[aVCClass alloc] init]; [vc performSelector:@selector(setDatArray:) withObject:[_resultData objectForKey:_dataSource[indexPath.row]]]; [vc performSelector:@selector(setTitle:) withObject:_dataSource[indexPath.row]];
    NSString * className = [NSString stringWithFormat:@"%@ViewController", _dataSource[indexPath.row]];    //创建视图控制器的Class    //使用class间接使用类名,即使不加头文件,也能创建对象。    //编译器要求直接引用类名等标识符,必须拥有声明。    Class aVCClass = NSClassFromString(className);    //创建vc对象    UIViewController * vc = [[aVCClass alloc] init];    [vc performSelector:@selector(setDatArray:) withObject:[_resultData objectForKey:_dataSource[indexPath.row]]];    [vc performSelector:@selector(setTitle:) withObject:_dataSource[indexPath.row]];


0 0