Pushviewcontroller:animated: The problem

Source: Internet
Author: User

1. In the APPDELEGATE.M:

2. In the SecondViewController.h:

3. In the FIRSTVIEWCONTROLLER.M:

4. In the SECONDVIEWCONTROLLER.M:

5. Finally, run the program and find the problem:Secondviewcontroller object is Firstviewcontroller object Navigationcontroller push,

The Secondviewcontroller object first invokes the execution of its-test method,-setwords: Method, Test2 method, Test3 method, in order,

Finally, the-viewdidload method of the Secondviewcontroller object is called to execute,

This leads to-setwords: _label.text = _words in the method, and becomes the [nil object settext:_words], which is equivalent to no execution, nature can not achieve the effect,

This is because the Uilabel object is only started in the-viewdidload method in the Secondviewcontroller object, so until then, _label is always an empty object (that is, the nil object)

6. Summary of issues:

b *b = [[B alloc] init];

[A.navigationcontroller pushviewcontroller:b Animated:yes];

[B methodinb];

Before iOS7, it is no problem to write this, call the process:

-loadview,-viewdidload,-viewwillappear,-viewdidappear, and finally-METHODINB

Since iOS7, the invocation process has changed:

[A.navigationcontroller pushviewcontroller:b Animated:yes];

The first call executed in B is-methodinb,-loadview,-viewdidload,-viewwillappear,-viewdidappear

7. Problem Solving:

since the-viewdidload method of the stack Ding Zi controller after push is executed by the last call, remove the-setwords: _label.text = _words in the method;

Instead, write _label.text = _words in the-viewdidload method, and you can assign it successfully!

Pushviewcontroller:animated: The problem

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.