简体   繁体   English

使用UILabel iOS的自定义UIView

[英]Custom UIView with UILabel iOS

I have a UIView with two UILabel that I want to reuse in more than one UIViewController . 我有一个带有两个UILabel的UIView ,我想在多个UIViewController重用。 I use storyboard and I assign a custom class alertView:UIView that I declared. 我使用情节alertView:UIView并分配了一个声明的自定义类alertView:UIView file AlertRemote.h 文件AlertRemote.h

@interface AlertRemote: UIView
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
-(void) setTextLabel;

file AlertRemote.m 文件AlertRemote.m

-(void) setTextLabel{
    [ _label1 setText:@"attention..."];
    [_label2 setText:@"the program..."];
}

file Controllo.m 文件Controllo.m

//the view present in the storyboard alertView linked to the uiview
@property (strong, nonatomic)IBOutlet AlertRemote *alertView; 
@property AlertRemote *alRemView;
[super viewDidLoad];
_alertView=_alRemView; [_alertView setTextLabel];
[_alertView setTextLabel];

if I put some breakpoints inside setTextLabel the code don't works thanks!! 如果我在setTextLabel中放置一些断点,代码将无法正常工作,谢谢!

In order for the custom alert to work, you need to initialise it. 为了使自定义警报起作用,您需要对其进行初始化。

AlertRemote *alRemView;

alRemView = [[AlertRemote alloc]init];
[alRemView setTextLabel];

I think you are not initializing the property alertview. 我认为您没有初始化属性alertview。 If you are initializing the property alertview then try to set directly with out using alremView. 如果要初始化属性alertview,请尝试使用alremView直接设置为不设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM