Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When put the exactly same code in a custom uitableview, mountains of warnings come to me... #21

Open
CaliosD opened this issue May 26, 2015 · 3 comments

Comments

@CaliosD
Copy link

CaliosD commented May 26, 2015

Hi, @smileyborg, I'm so excited to use PureLayout when lost in large numbers of constraints added for views. However, when I tried to put the same code in a custom UIView enbedded with a tableview, it shows lots of warnings in the console.
Here's the warnings.

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7fa5e1f5a300 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7fa5e1f51930(0)]>",
    "<NSLayoutConstraint:0x7fa5e1db41d0 UILabel:0x7fa5e1f52600'The correct API to use is...'.trailing == UITableViewCellContentView:0x7fa5e1f51930.trailing - 15>",
    "<NSLayoutConstraint:0x7fa5e1d95df0 H:|-(15)-[UILabel:0x7fa5e1f52600'The correct API to use is...']   (Names: '|':UITableViewCellContentView:0x7fa5e1f51930 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fa5e1db41d0 UILabel:0x7fa5e1f52600'The correct API to use is...'.trailing == UITableViewCellContentView:0x7fa5e1f51930.trailing - 15>

I wonder what on earth the difference is between setting constraints in a tableview and in a tableviewcontroller. As fresh to autolayout, what should I pay attention to when handling these kinds of problems? Could you give me some suggestions?

Hope to hear from you. Thanks in advance.

@smileyborg
Copy link
Owner

@Lilacxyz It's hard to say exactly why you're seeing this constraint exception, but basically the problem here is that the width of the table view cell's contentView is 0, and your constraints require at least 30 width (15 leading + 15 trailing).

So the issue is probably not with your constraints, but with how the cell is getting created/etc. You'll probably need to share a sample project if you need more help figuring out why this is happening.

@CaliosD
Copy link
Author

CaliosD commented May 29, 2015

You're exactly right! When I logged in heightForRowAtIndexPath, I found the width of cell's contentview is 0. I also upload my project here.[https://github.com/Lilacxyz/AutolayoutDemo]

Maybe I should learn more clearly what the differences between UITableViewController and UITableView is? Or UIViewController and UIView?

@fmaylinch
Copy link

Hi @CaliosD. I got a related problem, but in my case I think the size of the cell was 320 x 44 by default, which wasn't enough to contain my views (I had one view of height 60 so I needed 60 + margins minimum). I fixed that problem with this solution. I hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants