IOS, iOS 8

Source: Internet
Author: User

IOS, iOS 8

The previous content is supplemented and described.
Another experiment is required, so Test1ViewController and test1VC instance are used. TestViewController and testViewController are used before. This should not affect reading.

Problem

First read the code and create a subclass TestViewController (including the nib file) of UIViewController ):
The imageViewCourse and lbCourse attributes are added using the IBOutlet method of nib. For example:

Create Test1ViewController Add IBOutlet

Use the following code to redirect between uiviewcontrollers:

TestViewController *testViewController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];testViewController.imageViewCourse.image = image;testViewController.lbCourse.text = course;[self presentViewController:testViewController animated:YES completion:nil];

We use nib to load a TestViewController and assign values to its attributes, and then redirect. The problem is that after initWithNibName is executed, testViewController. imageViewCourse and testViewController. lbCourse are both nil, which means that after the jump to TestViewController, there is no content in imageViewCourse and lbCourse. For example:

IBOutlet content not updated Breakpoint debugging
Solution

Use the loadView method to trigger the loading of UIView in nib.

@property(null_resettable, nonatomic,strong) UIView *view; // The getter first invokes [self loadView] if the view hasn't been set yet. Subclasses must call super if they override the setter or getter.- (void)loadView; // This is where subclasses should create their custom view hierarchy if they aren't using a nib. Should never be called directly.- (void)loadViewIfNeeded NS_AVAILABLE_IOS(9_0); // Loads the view controller's view if it has not already been set.

That is:

TestViewController *testViewController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];[testViewController view];//[testViewController loadView];//[testViewController loadViewIfNeeded];testViewController.imageViewCourse.image = image;testViewController.lbCourse.text = course;[self.navigationController presentViewController:testViewController animated:YES completion:nil];

The result is as follows:

IBOutlet update content Breakpoint debugging

The code above is not explained too much. The three methods are actually the same.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.