Pregunta

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

¿Fue útil?

Solución

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];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top