在我cellForRowAtIndexPath:
方法,我有以下代碼:爲什麼我的UIButton沒有被添加到我的單元格中?
UIButton *signOutButton = [[UIButton alloc] init];
[signOutButton addTarget:self action:@selector(logoutButtonTapped) forControlEvents:UIControlEventTouchUpInside];
signOutButton.translatesAutoresizingMaskIntoConstraints = NO;
signOutButton.titleLabel.textColor = [UIColor colorWithRed:0/255.0 green:180/255.0 blue:35/255.0 alpha:1.0];
signOutButton.titleLabel.text = @"Sign Out";
[cell.contentView addSubview:signOutButton];
[cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:signOutButton
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:cell.contentView
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:50.0]];
[cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:signOutButton
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:cell.contentView
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:50.0]];
[cell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:signOutButton
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:cell.contentView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:-6.0]];
但它從來沒有顯示出來,當我加載細胞。我對自動佈局有點新鮮,所以任何人都可以弄清楚我做錯了什麼?
奇怪的是,如果我點擊按鈕應該執行的區域。
添加例外斷點所有異常並運行你的應用程序,如果在你的自動佈局規則的一些衝突,應停止執行,你應該能夠理解什麼是錯 – Manu