Search code examples
uiviewcontrolleruinavigationcontrollerxibarc4random

viewcontroller(xib)-random call in ios7


Does the following code call the viewcontrollers randomly? Here controller is my NSArray,where all my viewcontroller names are stored.

     [self.navigationController pushViewController:arc4random_uniform(controllers.count)      animated:YES];

Please help


Solution

  • arc4random_uniform returns integer value. If you want to implement this, then you might need to use this -

     [self.navigationController pushViewController:[controllers objectAtIndex:arc4random_uniform(controllers.count)] animated:YES];
    

    Update -

    NSString *className = [controllers objectAtIndex:arc4random_uniform(controllers.count)];
    UIViewController *viewController = (UIViewController*)[[NSClassFromString(@"NameofClass") alloc] init];
    [self.navigationController pushViewController:viewController animated:YES];