2014-01-27 74 views
0

以下代碼是否隨機調用viewcontrollers? 這裏的控制器是我的NSArray,其中存儲了所有的viewcontroller名稱。viewcontroller(xib) - 隨機呼叫ios7

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

請幫

回答

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]; 
+0

在運行時顯示錯誤。 –

+0

錯誤是什麼? – rishi

+0

- [__ NSCFConstantString useLayoutToLayoutNavigationTransitions]:無法識別的選擇器發送到實例0x41c1c –