Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用变量绑定窗体上的控件_Ios_Objective C - Fatal编程技术网

Ios 如何使用变量绑定窗体上的控件

Ios 如何使用变量绑定窗体上的控件,ios,objective-c,Ios,Objective C,我刚刚开始学习iOS课程,但看起来我已经错过了一些东西 我有一个带有UILabel和UIButton的表单。当用户按下按钮时,必须将按钮标题添加到标签文本中 这是我当前的CalculatorViewController。h: #import <UIKit/UIKit.h> @interface CalculatorViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *disp

我刚刚开始学习iOS课程,但看起来我已经错过了一些东西

我有一个带有UILabel和UIButton的表单。当用户按下按钮时,必须将按钮标题添加到标签文本中

这是我当前的CalculatorViewController。h:

#import <UIKit/UIKit.h>

@interface CalculatorViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *display;

@end
问题是self.display(和myDisplay)变量的值为零。看起来我需要做些什么来链接我的变量和表单上的控件。什么


提前谢谢。

不需要这条线

UILabel *myDisplay = self.display; 
您已经在接口文件中声明了标签

- (IBAction)digitPressed:(UIButton *)sender
{
   NSMutableString *string = [myDisplay.text stringByAppendingString:sender.titleLabel.text];
   myDisplay.text = string;
}

您需要将Interface Builder中的控件
UILabel
链接到
CalculatorViewController
类中的变量

文件的所有者(谈论Xib文件)很可能是您的
CalculatorViewController
,因此您需要控制并将文件的所有者(或代表VC的对象)拖动到控件中,然后会显示一个菜单,其中可能包含类中声明的
IBOutlet
变量,因此,选择要表示控件的控件


您可以通过两种方式检查此链接是否正确设置:(1)在Interface Builder中选择UILabel,并查看连接检查器中是否存在与变量的连接,或者(2)在代码中,您会在IBOutlet声明附近看到一个项目符号,如果项目符号为空,则未设置连接,如果项目符号已填充,则连接已设置。

谢谢。我以前做过控制+拖动,但现在看起来这个链接断了。我重新创建了它,现在一切都很好。谢谢
- (IBAction)digitPressed:(UIButton *)sender
{
   NSMutableString *string = [myDisplay.text stringByAppendingString:sender.titleLabel.text];
   myDisplay.text = string;
}