Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 在UIViewControl上添加自定义控件_Ios_Objective C_Uiviewcontroller - Fatal编程技术网

Ios 在UIViewControl上添加自定义控件

Ios 在UIViewControl上添加自定义控件,ios,objective-c,uiviewcontroller,Ios,Objective C,Uiviewcontroller,我已创建空控件-LogonErrorMessage.xib。在interface builder中放置了一个视图控件,并在其中放置了一个标签类的自定义消息控件 然后我创建了Objective-C类,该类也被命名为LogonErrorMessage.h和LogonErrorMessage.m 然后在LogonErrorMessage.xib中,我选择了视图控件,并在“自定义类”部分将类更改为LogonErrorMessage,以将*.xib绑定到类 现在,我尝试在MainViewControlle

我已创建空控件-LogonErrorMessage.xib。在interface builder中放置了一个视图控件,并在其中放置了一个标签类的自定义消息控件

然后我创建了Objective-C类,该类也被命名为LogonErrorMessage.h和LogonErrorMessage.m

然后在LogonErrorMessage.xib中,我选择了视图控件,并在“自定义类”部分将类更改为LogonErrorMessage,以将*.xib绑定到类

现在,我尝试在MainViewController上执行此操作:

LogonErrorMessage *logonError = [[LogonErrorMessage alloc] init];
logonError.iboMessageText.text = message;
logonError.frame= CGRectMake(0, 0, 307, 100);
[self.view addSubview:logonError];

消息控件未显示-问题出在哪里?

替换第一行:

LogonErrorMessage *logonError = [[LogonErrorMessage alloc] init];


没有可见的接口声明selectorOh wait,尽管LogonErrorMessage是一个视图控制器。编辑。可能重复的
//Loads all views named "MyView", in your case, replace "MyView" with your xib name.
NSArray *allCustomViews = [[NSBundle mainBundle] loadNibNamed:@"LogonErrorMessage" owner:self options:nil];

//Assuming there's only one MyView.xib
LogonErrorMessage* customView = [allCustomViews firstObject];