0

您好我正在制作一个需要随机页面生成器的应用程序,所以我想知道是否有办法在 xcode 中将随机页面生成器添加到情节提要

4

2 回答 2

0

if your intention is to generate random page (meaning view controllers) from a single command (e.g. Button) you can try this approach:

  1. In the storyboard, simply link the homeviewcontroller to the numbers of random view controllers you intend to create, by pressing control-drag and select push as the segue.

  2. Identify the numbers of segues independently, e.g segue1, segue2, ... segue100000 etc

  3. Lastly, just key in the following coding according to your headers and implementation names;

For the header of the homeviewcontroller.h

-(IBAction)RandomButton:(id)sender

For the implementation of the homeviewcontroller.m

-(IBAction)RandomButton:(id)sender {

NSArray *segues = @[@"segue1", @"segue2", ... ,@"segue10000"];
NSString *segueID = segues[arc4random_uniform(segues.count)];
[self performSegueWithIdentifier: segueID sender: sender];

}

  1. Now try to run it. It should work fine! Cheers.
于 2013-06-01T02:48:52.730 回答
0

我所知道的没有开箱即用的东西(并且鉴于每个应用程序都有不同的“页面”概念,我不确定是否存在通用方法。(不过,我不使用故事板,所以我有点在我的舒适区之外。)

生成随机数很容易,您可以将其用作某些方法的输入,例如,挑选一个索引视图控制器并将其推送到导航堆栈上。但这是假设的,完全取决于您的应用程序架构。

需要详细说明吗?

于 2012-05-11T21:20:06.263 回答