简体   繁体   中英

Adding and controlling view controllers in storyboard in xcode

I am new to iphone programming and I have created a special scenario. I am pretty sure that it will answer most of my questions for creating my app. Here it is. (i HAVE 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 .

Suppose I have added a progress View (Graphically) on the view Controller. Also I have added another viewController on storyboard and made its background black.

When i run the app my first viewController with progress view shows up

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.

2- After showing progress within 5 seconds it should switch to other view Controller with black background.

3- I have created a class file " MySecondController " How can i link this class to my black screen 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. This is the assistant editor. Select the storyboard, select the ViewController, then select the assistant editor. A second editor will appear. Make sure it's editing ViewController.h. Press control and drag from the progress view in the storyboard to a point inside the ViewController interface definition. (right after the line that looks like this: @interface ViewController : UIViewController ) You'll be prompted to type an outlet name. Type something like "progressView" (no quotes).

1b) See below to set the progress view to a value.

2) See below to present the second view controller after a delay.

3) In the storyboard, drag a new viewcontroller onto the canvas. On the identity inspector (try the icons under the tuxedo icon, the third from the left is identity), set it's class to MySecondController. Select the original ViewController, press control and drag from it's status bar (the top of it) to the viewcontroller you just added. This will create a segue. A menu will appear asking what kind of segue you want. Make the segue modal for now. 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".

Back to questions 1b and 2) Go to ViewController.m and add this code...

@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. For that, you'll need to read about NSTimer. You can set one up to send you a message periodically, and you can adjust the progressView each time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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