类名写入plist文件,动态引入类

来源:互联网 发布:ubuntu撤销命令 编辑:程序博客网 时间:2024/05/01 18:16

   把类名写入plist文件,动态引入类  

NSString *classNameKey = [moduleData objectForKey:@"class"];

    

    NSDictionary *moduleDic = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Module" ofType:@"plist"]];

    

    NSString *className = [moduleDic objectForKey:classNameKey];

    把对应的字符串映射成对应的类

    Class moduleClass = NSClassFromString(className);

    

    NSObject *module = [moduleClass new];

    

    UIViewController *moduleVC = nil;

    

    if ([module respondsToSelector:@selector(init)])

    {

        NSLog(@"module vc init");

        moduleVC = [module performSelector:@selector(init)];

    }

    if (!moduleVC)

    {

        NSLog(@"notice view");

        moduleVC = [[[NoticeViewController alloc] initWithNibName:nil bundle:nil] autorelease];

    }

    //传参数

    if ([moduleVC respondsToSelector:@selector(getModuleData:)])

    {

        [moduleVC performSelector:@selector(getModuleData:) withObject:moduleData];

    }

    //修改frame

    if ([moduleVC respondsToSelector:@selector(changeFrameWithRect:)])

    {

        [moduleVC performSelector:@selector(changeFrameWithRect:) withObject:NSStringFromCGRect(rect)];

    }

    //显示返回按钮

    if (isShow && [moduleVC respondsToSelector:@selector(createNavBar)])

    {

        [moduleVC performSelector:@selector(createNavBar) withObject:nil];

    }

    

    [module autorelease];

0 0
原创粉丝点击