Your First iOS App--蘋果官方iOS文檔學習

來源:互聯網
上載者:User

標籤:

 1 // 2 //  ViewController.m 3 //  HelloWorld 4 // 5 //  6 // 7 #import "ViewController.h" 8 @interface ViewController () 9 @end10 @implementation ViewController11 @synthesize userName=_userName;12 @synthesize textField=_textField;13 @synthesize label=_label;14 - (void)viewDidLoad {15     //[self setTextField:nil];一初始化為空白,注釋掉後,label可以正常擷取使用者輸入的值。16     //[self setLabel:nil];文檔45頁說明加上了這些可能是為了說有什麼作用,記得刪除,不然會影響後面的label輸出顯示內容。17     //[super viewDidLoad];18     // Do any additional setup after loading the view, typically from a nib.19 }20 - (void)didReceiveMemoryWarning {21     [super didReceiveMemoryWarning];22     // Dispose of any resources that can be recreated.23 }24 - (IBAction)changeGreeting:(id)sender {25     self.userName = self.textField.text;26     NSString *nameString = self.userName;27     NSLog(@"%@",nameString);28     if ([nameString length] == 0) {29         nameString = @"World";30         NSLog(@"111");31     }32     NSLog(@"222");33     NSString *greeting = [[NSString alloc]initWithFormat:@"Hello,%@!",nameString];34     NSLog(@"%@",greeting);35     self.label.text = greeting;36       NSLog(@"333");37 }38 - (BOOL)textFieldShouldReturn:(UITextField *)theTextField{39     if (theTextField == self.textField) {40         [theTextField resignFirstResponder];41     }42     return YES;43 44 }45 @end

15、16行是Your First ios App 第45頁上面加上去的,用的有道翻譯軟體也沒有提示說,這兩句會影響最終案例的效果顯示。代碼中加了很多nslog輸出,是為了做測試,這個方法屢試不爽。第二張中右下角有代碼輸出提示。在27行加上nslog後,輸出竟然是(null),所以判斷,使用者輸入的內容沒有被擷取。這下好判斷問題出現在哪了,因為對Objective文法不熟悉,先注釋了,一運行,結果成了,這兩句語句我得仔細查查。

Your First iOS App--蘋果官方iOS文檔學習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.