zoukankan      html  css  js  c++  java
  • Your First iOS App--苹果官方iOS文档学习

     1 //
     2 //  ViewController.m
     3 //  HelloWorld
     4 //
     5 // 
     6 //
     7 #import "ViewController.h"
     8 @interface ViewController ()
     9 @end
    10 @implementation ViewController
    11 @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语法不熟悉,先注释了,一运行,结果成了,这两句语句我得仔细查查。

  • 相关阅读:
    同步回调函数与异步回调函数示例
    关于js中的回调函数callback
    JavaScript callback function 回调函数的理解
    CSS“隐藏”元素的几种方法的对比
    JSF中run项目时候Tomcat8启动不了的一种方法
    The JSP specification requires that an attribute name is
    [转载]Windows 2003 R2 SP2 VOL 企业版(简体中文)
    ${pageContext.request.contextPath}相关问题总结
    最简单的java浏览器
    【转】像素存储容量的计算
  • 原文地址:https://www.cnblogs.com/liqiwa/p/5171262.html
Copyright © 2011-2022 走看看