【问题标题】:Custom UIView with UILabel iOS使用 UILabel iOS 自定义 UIView
【发布时间】:2014-05-30 09:53:24
【问题描述】:

我有一个 UIView 和两个 UILabel,我想在多个 UIViewController 中重复使用它们。我使用情节提要并分配了我声明的自定义类alertView:UIView。 文件 AlertRemote.h

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

文件 AlertRemote.m

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

文件 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];

如果我在 setTextLabel 中放置一些断点,代码将不起作用 谢谢!!

【问题讨论】:

  • 为什么不直接使用AlertRemote IBOutlet 来设置文本呢?需要alRemView 吗?你做什么用的?

标签: ios uiview uilabel


【解决方案1】:

为了使自定义警报起作用,您需要对其进行初始化。

AlertRemote *alRemView;

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

【讨论】:

    【解决方案2】:

    我认为您没有初始化属性警报视图。如果您正在初始化属性 alertview 则尝试直接设置而不使用 alremView。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2017-04-26
      • 1970-01-01
      相关资源
      最近更新 更多