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.