加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – UITextfield.text返回null

发布时间:2020-12-14 19:38:53 所属栏目:百科 来源:网络整理
导读:假设有一个 iphone项目的代码是: IBOutlet UITextField* numberDisplay; @property (strong,nonatomic) IBOutlet UITextField *numberDisplay; 在实现文件和 @synthesize numberDisplay; 在实施文件中.同样在实施中 -(IBAction)numberClicked:(id)sender {
假设有一个 iphone项目的代码是:

IBOutlet UITextField* numberDisplay;
      @property (strong,nonatomic) IBOutlet UITextField *numberDisplay;

在实现文件和

@synthesize numberDisplay;

在实施文件中.同样在实施中

-(IBAction)numberClicked:(id)sender {  
     UIButton *buttonPressed = (UIButton *)sender;  
    int val = buttonPressed.tag;  
     if ( [numberDisplay.text compare:@"0"] == 0 ) {  
    numberDisplay.text =[NSString  stringWithFormat:@"%d",val ];  

  } else {  
      numberDisplay.text = [NSString  
                     stringWithFormat:@"%@%d",numberDisplay.text,val ];  
    }

   }

当我运行应用程序时,UITextfield中没有显示任何显示,即使连接是使用IB进行的,并且已经证明是通过查看检查器进行的.即使作为测试,如果我添加线条

numberDisplay.text = @"a";
    NSLog(@"the value is %@",numberDisplay.text);   
    NSLog(@"the value is %@",numberDisplay);

我得到“两个案例中的值都是(null).任何想法.

有人可以告诉我这两行有什么问题吗?谢谢.

谢谢大家.我从零开始,现在一切正常.看起来我有一个贴错标签的文件.

解决方法

空对象可以接收选择器,它们忽略它们并返回null对象.你遇到的情况是这样的:

[(UITextField*)nil setText:@"a"];
NSLog(@"the value is %@",[(UITextField*)nil text]);

确保文本字段不为空

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读