An careless wrong pointer.

Source: Internet
Author: User

Try to achieve the following effect:

Enter a character in the box and click the button to change the value of the label box:

ViewController.h

1 #import <UIKit/UIKit.h> 2  3@interface  viewcontroller: Uiviewcontroller  4  5 @property (nonatomic,assign) iboutlet Uitextfield *input1; 6 @property (nonatomic,assign) iboutlet UILabel *output1; 7 8 9 - (ibaction) click1; Ten @end

Viewcontroller.m

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 5 @end6 7 @implementationViewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; One     //additional setup after loading the view, typically from a nib. A } -  -- (void) didreceivememorywarning { the [Super didreceivememorywarning]; -     //Dispose of any resources the can be recreated. - } -- (void) click1{ + //nsstring *input1 = _input1.text; - //nsstring *output1 = _output1.text; + //output1 = input1; ANSString *INPUT1 =_input1.text; at_output1.text =input1; -NSString *OUTPUT1 =_output1.text; -      -      -NSLog (@"test:%@,%@", INPUT1,OUTPUT1); -      in      - } to  + @end

Click1 method Inside I was written in the beginning of the commented out 3 lines, after the run normal printing, but the label's text value has not changed. The reason is that "output1 = input1" Only changes the output1 point, so output1 this point to the address that input1 points to, and _output1 's set method is not called. Well, I don't know why I started writing orz like that.

An careless wrong pointer.

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.