如何从NSString名称动态创建任何UIViewController iOS7.1

如何从NSString名称动态创建任何UIViewController iOS7.1,ios7,uiviewcontroller,xcode5,Ios7,Uiviewcontroller,Xcode5,我想从NSString名称(buttonSelected.viewControllerID)创建一个UIViewController,考虑到类名与storyboardIdentifier相同,如何做到这一点???,目前我有两个ViewController的以下代码,但我只想一次完成 if ([buttonSelected.typeOfContent isEqualToString:@"AtencionClienteDetalleVC"]) { if ([[function

我想从NSString名称(buttonSelected.viewControllerID)创建一个UIViewController,考虑到类名与storyboardIdentifier相同,如何做到这一点???,目前我有两个ViewController的以下代码,但我只想一次完成

    if ([buttonSelected.typeOfContent isEqualToString:@"AtencionClienteDetalleVC"]) {
        if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Notification"
                                        message:[NSString stringWithFormat:@"screen destination must not be empty"]
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
        }
        else{
            AtencionClienteDetalleVC *viewController = [self.storyboard instantiateViewControllerWithIdentifier:buttonSelected.viewControllerID];

            viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
            viewController.itemsCatalog = buttonSelected.viewControllerParameters;


            [self.navigationController pushViewController:viewController animated:YES];

        }
        return;
    }


if ([buttonSelected.typeOfContent isEqualToString:@"ListadoVideos"]) {
        if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Notification"
                                        message:[NSString stringWithFormat:@"screen destination must not be empty"]
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
        }
        else{
            ListadoVideos *viewController = [self.storyboard instantiateViewControllerWithIdentifier:buttonSelected.viewControllerID];

            viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
            viewController.itemsCatalog = buttonSelected.viewControllerParameters;


            [self.navigationController pushViewController:viewController animated:YES];

        }
        return;
    }

只需将所有buttonSelected.typeOfContent设置为“ViewController”,然后替换当前代码即可:

if ([buttonSelected.typeOfContent isEqualToString:@"ViewController"]) {
        if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Notification"
                                        message:[NSString stringWithFormat:@"screen destination must not be empty"]
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
        }
        else{
            NSString *myUIViewControllerClassName   = buttonSelected.viewControllerID;
            Class     myClass                       = NSClassFromString(myUIViewControllerClassName);
            NSObject *myObject                      = [myClass new];
            if( [myObject isKindOfClass:[UIViewController class]] ){
                UIViewController *rightViewController   = (UIViewController *) myObject;
                rightViewController                     = [self.storyboard instantiateViewControllerWithIdentifier:myUIViewControllerClassName];
                rightViewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
                [self.navigationController pushViewController:rightViewController animated:YES];
            }
        }
        return;
    }

只需将所有buttonSelected.typeOfContent设置为“ViewController”,然后替换当前代码即可:

if ([buttonSelected.typeOfContent isEqualToString:@"ViewController"]) {
        if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Notification"
                                        message:[NSString stringWithFormat:@"screen destination must not be empty"]
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
        }
        else{
            NSString *myUIViewControllerClassName   = buttonSelected.viewControllerID;
            Class     myClass                       = NSClassFromString(myUIViewControllerClassName);
            NSObject *myObject                      = [myClass new];
            if( [myObject isKindOfClass:[UIViewController class]] ){
                UIViewController *rightViewController   = (UIViewController *) myObject;
                rightViewController                     = [self.storyboard instantiateViewControllerWithIdentifier:myUIViewControllerClassName];
                rightViewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
                [self.navigationController pushViewController:rightViewController animated:YES];
            }
        }
        return;
    }

只需将所有buttonSelected.typeOfContent设置为“ViewController”,然后替换当前代码即可:

if ([buttonSelected.typeOfContent isEqualToString:@"ViewController"]) {
        if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Notification"
                                        message:[NSString stringWithFormat:@"screen destination must not be empty"]
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
        }
        else{
            NSString *myUIViewControllerClassName   = buttonSelected.viewControllerID;
            Class     myClass                       = NSClassFromString(myUIViewControllerClassName);
            NSObject *myObject                      = [myClass new];
            if( [myObject isKindOfClass:[UIViewController class]] ){
                UIViewController *rightViewController   = (UIViewController *) myObject;
                rightViewController                     = [self.storyboard instantiateViewControllerWithIdentifier:myUIViewControllerClassName];
                rightViewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
                [self.navigationController pushViewController:rightViewController animated:YES];
            }
        }
        return;
    }

只需将所有buttonSelected.typeOfContent设置为“ViewController”,然后替换当前代码即可:

if ([buttonSelected.typeOfContent isEqualToString:@"ViewController"]) {
        if ([[functions removeBlanksFromString:buttonSelected.viewControllerID] isEqualToString:@""]) {
            [[[UIAlertView alloc] initWithTitle:@"Notification"
                                        message:[NSString stringWithFormat:@"screen destination must not be empty"]
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil] show];
        }
        else{
            NSString *myUIViewControllerClassName   = buttonSelected.viewControllerID;
            Class     myClass                       = NSClassFromString(myUIViewControllerClassName);
            NSObject *myObject                      = [myClass new];
            if( [myObject isKindOfClass:[UIViewController class]] ){
                UIViewController *rightViewController   = (UIViewController *) myObject;
                rightViewController                     = [self.storyboard instantiateViewControllerWithIdentifier:myUIViewControllerClassName];
                rightViewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
                [self.navigationController pushViewController:rightViewController animated:YES];
            }
        }
        return;
    }