简体   繁体   English

在xcode中添加和控制storyboard中的视图控制器

[英]Adding and controlling view controllers in storyboard in xcode

I am new to iphone programming and I have created a special scenario. 我是iphone编程的新手,我创建了一个特殊场景。 I am pretty sure that it will answer most of my questions for creating my app. 我很确定它会回答我创建应用程序的大部分问题。 Here it is. 这里是。 (i HAVE Xcode 4.2 ) (我有Xcode 4.2

I have created a universal application with storyboard and single view. 我创建了一个带有故事板和单一视图的通用应用程序。

I have appDelegate , storyboard files and a class file ViewController.h/m for my initial ViewController . 我有我的初始ViewController appDelegatestoryboard files和类文件ViewController.h/m

Suppose I have added a progress View (Graphically) on the view Controller. 假设我在视图控制器上添加了一个progress View (Graphically)。 Also I have added another viewController on storyboard and made its background black. 此外,我在故事板上添加了另一个viewController ,并使其背景为黑色。

When i run the app my first viewController with progress view shows up 当我运行应用程序时,我的第一个viewController显示进度视图

Now my questions are 现在我的问题是

1- How can I link my progress view in the class file and how can i set it progress for 5 seconds. 1-如何在类文件中链接我的进度视图以及如何将进度设置为5秒。

2- After showing progress within 5 seconds it should switch to other view Controller with black background. 2-在5秒内显示进度后,应切换到黑色背景的其他视图控制器。

3- I have created a class file " MySecondController " How can i link this class to my black screen viewController. 3-我创建了一个类文件“ MySecondController ”如何将此类链接到我的黑屏viewController。

These are easy questions. 这些都很简单。 I hope I get answer to these. 我希望我能回答这些问题。 If anyone have tutorials linking to these questions do post. 如果有人有教程链接到这些问题,请发布。 I have tried and haven't found useful. 我尝试过但没有找到有用的东西。

Best Regards 最好的祝福

1a) On the upper right of the xcode window, there's a tuxedo icon. 1a)在xcode窗口的右上角,有一个燕尾服图标。 This is the assistant editor. 这是助理编辑。 Select the storyboard, select the ViewController, then select the assistant editor. 选择故事板,选择ViewController,然后选择助理编辑器。 A second editor will appear. 将出现第二个编辑器。 Make sure it's editing ViewController.h. 确保它正在编辑ViewController.h。 Press control and drag from the progress view in the storyboard to a point inside the ViewController interface definition. 按控制并从故事板中的进度视图拖动到ViewController接口定义内的一个点。 (right after the line that looks like this: @interface ViewController : UIViewController ) You'll be prompted to type an outlet name. (在看起来像这样的行之后: @interface ViewController : UIViewController )系统将提示您输入插座名称。 Type something like "progressView" (no quotes). 输入类似“progressView”(没有引号)的内容。

1b) See below to set the progress view to a value. 1b)参见下文将进度视图设置为值。

2) See below to present the second view controller after a delay. 2)延迟后见下面的第二个视图控制器。

3) In the storyboard, drag a new viewcontroller onto the canvas. 3)在故事板中,将新的viewcontroller拖到画布上。 On the identity inspector (try the icons under the tuxedo icon, the third from the left is identity), set it's class to MySecondController. 在身份检查器上(尝试tuxedo图标下的图标,左边的第三个是身份),将它的类设置为MySecondController。 Select the original ViewController, press control and drag from it's status bar (the top of it) to the viewcontroller you just added. 选择原始ViewController,按下控件并从其状态栏(顶部)拖动到刚添加的viewcontroller。 This will create a segue. 这将创建一个segue。 A menu will appear asking what kind of segue you want. 将出现一个菜单,询问您想要什么类型的segue。 Make the segue modal for now. 现在制作segue模态。 Click on the new segue to select it, then click on the attributes inspector (right next to identity inspector) give the segue an identifier, call it "MySecondControllerSegue". 单击新的segue选择它,然后单击属性检查器(身份检查器旁边)给segue一个标识符,称之为“MySecondControllerSegue”。

Back to questions 1b and 2) Go to ViewController.m and add this code... 回到问题1b和2)转到ViewController.m并添加此代码...

@synthesize progressView;
// this creates methods on self to access the progress view

// this is called after the view appears
- (void)viewDidAppear:(BOOL)animated {

    // do inherited behavior
    [super viewDidAppear:animated];

    // set the progress view value to a number between 0.0-1.0, representing percentage
    // notice how we used the synthesized getter: self.progressView
    self.progressView.progress = 0.5;  

    // call another method with no parameters after five seconds
    [self performSelector:@selector(doSegue) withObject:nil afterDelay:5.0];
}

- (void)doSegue {
    // run the segue that you created in IB
    [self performSegueWithIdentifier:@"MySecondControllerSegue" sender:self];
}

Build and run. 建立并运行。

After this is working, you'll probably want to show that progress view advancing from the 0.0 position to 1.0 over the course of five seconds. 在此工作之后,您可能希望在五秒钟内显示进度视图从0.0位置前进到1.0。 For that, you'll need to read about NSTimer. 为此,您需要阅读有关NSTimer的信息。 You can set one up to send you a message periodically, and you can adjust the progressView each time. 您可以设置一个定期向您发送消息,并且您可以每次调整progressView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM