문제

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

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top