1 //2 //VIEWCONTROLLER.M3 //HelloWorld4 //5 // 6 //7 #import "ViewController.h"8 @interfaceViewcontroller ()9 @endTen @implementationViewcontroller One @synthesizeUsername=_username; A @synthesizeTextfield=_textfield; - @synthesizeLabel=_label; -- (void) Viewdidload { the //[self settextfield:nil]; once initialized to null, when commented out, the label can normally get the value entered by the user. - //[self setlabel:nil]; Document 45 page description Add these may be to say what role, remember to delete, otherwise it will affect the label output after the display content. - //[Super Viewdidload]; - //additional setup after loading the view, typically from a nib. + } -- (void) didreceivememorywarning { + [Super didreceivememorywarning]; A //Dispose of any resources the can be recreated. at } --(Ibaction) Changegreeting: (ID) Sender { -Self.username =Self.textField.text; -NSString *namestring =Self.username; -NSLog (@"%@", namestring); - if([namestring length] = =0) { inNamestring =@" World"; -NSLog (@"111"); to } +NSLog (@"222"); -NSString *greeting = [[NSString Alloc]initwithformat:@"hello,%@!", namestring]; theNSLog (@"%@", greeting); *Self.label.text =greeting; $NSLog (@"333");Panax Notoginseng } --(BOOL) Textfieldshouldreturn: (Uitextfield *) thetextfield{ the if(Thetextfield = =Self.textfield) { + [Thetextfield Resignfirstresponder]; A } the returnYES; + - } $ @end
15, 16 lines is your first iOS App on the 45th page added up, with the Youdao translation software also did not suggest that the two sentences will affect the final case effect display. A lot of nslog output is added to the code to do the testing. There is a code output hint in the lower right corner of the second sheet. After 27 lines plus nslog, the output is (null), so it is judged that the user entered the content is not obtained. This good judgment problem appears, because of objective grammar unfamiliar, first annotated, a run, the result has become, the two sentences I have to carefully check.
Your first iOS app--Apple official iOS document learning