viewcontroller(xib) - ios7中的随机调用

时间:2014-01-27 09:17:14

标签: uiviewcontroller uinavigationcontroller xib arc4random

以下代码是否随机调用viewcontrollers? 这里的控制器是我的NSArray,其中存储了我的所有viewcontroller名称。

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

请帮忙

1 个答案:

答案 0 :(得分:0)

arc4random_uniform返回整数值。如果你想实现这个,那么你可能需要使用它 -

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

更新 -

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