初始化后,UIButton为零

时间:2015-09-08 12:51:05

标签: ios uibutton

我正在尝试创建一个UIButton - 这在我使用模拟器时工作正常,但是当我尝试设备时按钮不会出现。

[self.followButton setImage:[UIImage new] forState:UIControlStateNormal];
[self.followButton setTitle:@"EDIT" forState:UIControlStateNormal];
self.profMoreButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *icon = [[UIImage imageNamed:@"More"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[self.profMoreButton.imageView setContentMode:UIViewContentModeScaleAspectFit];
[self.profMoreButton setImage:icon forState:UIControlStateNormal];
[self.profMoreButton.imageView setTintColor:[UIColor Primary]];
[self.profMoreButton addTarget:self action:@selector(morePressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.profMoreButton];
[self.profMoreButton mas_makeConstraints:^(MASConstraintMaker *make) {
    make.size.equalTo(self.followButton.mas_height).multipliedBy(0.6);
    make.centerY.equalTo(self.followButton);
    make.left.equalTo(self.followButton.mas_right).with.offset(8);
}];
if (!self.profMoreButton) {
    NSLog(@"WHY!?????");
}

在我的iPhone 6上,最后的NSLog始终打印,并且按钮不会出现,除非我在顶部放置一个断点并逐步完成。

2 个答案:

答案 0 :(得分:1)

self.profMoreButton被宣布为弱IBOutlet,我删除了IBOutlet并将其更改为strong。现在它可以工作

答案 1 :(得分:-2)

我认为你没有给阿拉伯联合酋长国

{{1}}