У меня проблема с программным обеспечением iOS UIButton
.iOS UIButton клик не работает
У меня есть UIButton
:
- (UIButton *)compareButton
{
if (!_compareButton)
{
NSString *title = TITLE;
NSDictionary *attributes = TITLE_ATTRIBUTES;
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attributes];
_compareButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 20.0f, 100.0f, 44.0f)];
_compareButton.backgroundColor = [UIColor redColor];
[_compareButton setAttributedTitle:attributedTitle forState:UIControlStateNormal];
[_compareButton addTarget:self action:@selector(buttonCompareClicked:) forControlEvents:UIControlEventTouchUpInside];
}
return _compareButton;
}
UIButton
щелчки должны быть обработаны методом
- (void)buttonCompareClicked:(UIButton *)sender
Кроме того, у меня есть UIView
:
- (UIView *)header
{
if (!_header)
{
UIView *header = [[UIView alloc] init];
header.backgroundColor = [UIColor whiteColor];
[self.view addSubview:header];
_header = header;
}
return _header;
}
Моя кнопка подвид из вид:
[self.header addSubview:self.compareButton];
Все взаимодействия пользователя включены:
self.view.userInteractionEnabled = YES;
self.header.userInteractionEnabled = YES;
self.compareButton.userInteractionEnabled = YES;
Несмотря на это, нажатие кнопки не вызывает вызов метода.
Где может быть проблема с этим?
Вы установили соединение IBAction? – abhishekkharwar
Используете ли вы раскадровки или любой файл XIB, содержащий кнопку? –
Я не вижу, где вы устанавливаете фрейм заголовка, или добавляете ограничения, чтобы выложить его с помощью автоматического макета. Он может иметь нулевую ширину и высоту. Попробуйте установить свойство 'backgroundColor', чтобы вы могли видеть, имеет ли он допустимый размер. – johnpatrickmorgan