Giter VIP home page Giter VIP logo

tableviewcellwithautolayoutios8's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tableviewcellwithautolayoutios8's Issues

Additional UIViews below last UILabel produce autolayout warnings

Hi smileyborg, this saves a TON of time... Can't thank you enough.

Can you help me with a problem I'm having? I am running into autoLayout problems when trying to add an additional object to the sample code on iOS8. It's probably me doing something wrong.. But I just can't see it.

Creating a UIView under the bottom UILabel and giving the autoLayout constraints below will display correctly, but with lots of autoLayout warnings followed by an attempt to break constraint...

Can you help me figure out what am I doing wrong?

var square: UIView = UIView.newAutoLayoutView()

square.backgroundColor = UIColor.blackColor()
contentView.addSubview(square)

square.autoPinEdge(.Top, toEdge: .Bottom, ofView: bodyLabel, withOffset: 10.0)
square.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets)
square.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets)
square.autoPinEdgeToSuperviewEdge(.Bottom, withInset: kLabelVerticalInsets)
square.autoSetDimension(ALDimension.Height, toSize: 40)

untitled

I think we need know something

   When  learn the new autoLayout feature in ios8,I found that if devper add the contrains with Code ( but not complete,app may still work well when devper manual caculate the cell height ),the new feature will not work!
   SO,devper must add constains completely!

Table view jumps when scrolling up

How to recreate:

  1. Scroll down to the bottom
  2. Add a couple of rows by pressing the + button
  3. Scroll up - the table view will start jumping

I have such issue in my own project. I have an infinite feed where I load data dynamically whenever the user scrolls to the bottom. However, when I want to scroll up it jumps and gives you a bad user experience.

Did you guys figured out this issue?

swift: compiler error

Hello, I've just cloned the project and tried to compile swift version without any modifications, but I've run into following issue:

Xcode Version 6.4 (6E35b), iOS SDK 8.4
screen shot 2015-08-16 at 18 18 26

Do you compile project without any problems? Thanks
Filip

UILayoutPriority in Swift

Even in Xcode 6.1 I cannot set the UILayoutPriority programmatically in Swift(perhaps it's me). I noticed that you filed a radar on this. Any updates on the status?

        // FIXME 7-Jun-14 Xcode 6b1: Apple Bug Report rdar://17220525: The UILayoutPriority enum is not compatible with Swift yet!

Title label does not grow to size

I've been having a hard time figuring out the self-sizing cells for the past two days. I think I've re-read your answer here on SO 20 times; I want to say I understand how this works, but I can't get this to work for the life of me.

I finally got fed up, wiped out all of my work, copy-pasted the UITableViewCell & UITableViewController subclasses from this project into mine and get the following:
screen shot 2015-12-23 at 10 24 44 pm

Here's my cell and controller (basically copy-paste besides the label text):
screen shot 2015-12-23 at 10 24 24 pm

And my storyboard attributes so you know no funny-business is going on there:
screen shot 2015-12-23 at 10 31 14 pm
screen shot 2015-12-23 at 10 31 20 pm

UIView-Encapsulated-Layout-Height constraint issue in iOS 8

Hi,

I tried your example and its working fine if we have only two or three labels in our cell, if we try to add more labels to the cell , we are getting the below error in xcode 6

"<NSLayoutConstraint:0x7ff368733f60 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff3687bedf0(44)]>",
"<NSLayoutConstraint:0x7ff368734a70 V:|-(10)-[UILabel:0x7ff3687bec20'Apple SD Gothic Neo'] (Names: '|':UITableViewCellContentView:0x7ff3687bedf0 )>",
"<NSLayoutConstraint:0x7ff3687352b0 V:[UILabel:0x7ff3687bec20'Apple SD Gothic Neo']-(>=10)-[UILabel:0x7ff36872a9c0'Lorem ipsum dolor sit ame...']>",
"<NSLayoutConstraint:0x7ff3687358e0 V:[UILabel:0x7ff36872a9c0'Lorem ipsum dolor sit ame...']-(>=10)-[UILabel:0x7ff3687c0450'Lorem ipsum dolor sit ame...']>",
"<NSLayoutConstraint:0x7ff368735c00 V:[UILabel:0x7ff3687c0450'Lorem ipsum dolor sit ame...']-(>=10)-[UILabel:0x7ff3687c0040'Lorem ipsum dolor sit ame...']>",
"<NSLayoutConstraint:0x7ff368736200 V:[UILabel:0x7ff3687c0040'Lorem ipsum dolor sit ame...']-(>=10)-[UILabel:0x7ff36872acf0'Lorem ipsum dolor sit ame...']>",
"<NSLayoutConstraint:0x7ff368735e80 UILabel:0x7ff36872acf0'Lorem ipsum dolor sit ame...'.bottom == UITableViewCellContentView:0x7ff3687bedf0.bottom - 10>"

Thanks,
Krishna

Trouble while rotating device

Hello mate. I have been using your solution to create auto-layout UITableViews and UITableViewCell basically since you released it for iOS 7, it is great

Back then I made a few modifications to allow different constraints to be placed for portrait and landscape orientations, basically it was done by adding an observer for orientation changes to the table view cell that calls "setNeedsUpdateConstraints" and at the "updateConstraints" method I remove and add the constraints needed to change the layout on the cells.

It was working ok on iOS 7 but now on iOS 8 it doesn't seem to work correctly, I already updated it to use UITableViewAutomaticDimension with no luck. Do you have any ideas why this could be happening?

Scrolling to bottom

First of all, thank you so much for this example app, it helped me a lot when moving to pure auto layout auto sizing table view cells. I've noticed a strange problem in my app and had the same problem with this example app too.

Let's say I want the table to start off scrolled all the way to the bottom, the user then has to scroll up to see previous items (like the Messages app, or any chap page). So in viewWillAppear: I'd call something like this:

NSUInteger index = [self.tableView numberOfRowsInSection:0] - 1;
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

What you'll notice is that the table is scrolled to somewhere in the middle instead of the bottom, and when you scroll up, the previous cells pop into place while causing the entire table to jump. It's very very ugly.

I've also asked about the problem on stackoverflow but no answers yet. Maybe you have any ideas on how to solve this?

Wrong margins with iOS 8.1 and 8.2

When using your demo as is with current Xcode 7.3 and e.g. iOS Simulator iPad Air 2 on iOS 8.1 (12B411), the margins are wrong compared to the separator insets:

screenshot 2016-04-14 01 27 03

After trying this I used the nib instead and made the following adjustments (as you had hardcoded +/- 15 points as margins), which should work:

CellIdentifier: Preserve Superview margins checked
Content View: Preserve Superview margins checked
Leading/Trailing Constraints: Each leading/trailing set to constant 0, but pinned to superview's margin instead of superview

Expected:
Margins automatically adjusted

Actual:

screenshot 2016-04-14 01 31 10

screenshot 2016-04-14 01 33 12

I am trying this for about a week (!), do you know of any official way to get the margins right with iOS 8.1 and 8.2? Btw: Margins are broken when used in Form Sheets with iPhone 6+ in Landscape with iOS 9.x, too (they differ from the separator insets as well).

Any idea?

Major Performance Issue with non-English UTF8 Strings

Hello,

The project has major performance issue with non-English UTF8 strings. For reproduce the problem, just change the sample data test in "modal.swift" line 39 as follows:

let loremIpsum = "این یک متن تست است. تستی برای تست کردن یک تست..این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست.این یک متن تست است. تستی برای تست کردن یک تست."

How could we resolve this?

Adding new cell while scrolling causes table view to jump

If you...

  1. Swipe the tableview to scroll it fast (or slow).
  2. Hit the '+' button while it's scrolling

... the tableview jumps up before it continues scrolling from a random location. This doesn't happen if the tableview is not scrolling (i.e. it's stationary) when you add cells. I'm assuming this is another UITableView auto-sizing bug that has something to do with scrollView frame and offset calculations when the table view is being scrolled.

Anyone have any ideas for a workaround? I wanted to check before I try to get too clever.

[BUG]when change to another view and back, the visible row is wrong

To reproduce this, first add a TabbarController in RJAppDelegate.m

UIViewController *dummyVC = [[UIViewController alloc] init];
[dummyVC.view setBackgroundColor:[UIColor redColor]];

self.tabbarController = [[UITabBarController alloc] init];
self.tabbarController.viewControllers = @[self.navigationController,dummyVC];

self.window.rootViewController = self.tabbarController;

Run the code, scroll to the end. Switch to tab 2, and switch back.
You will see now the scroll position is not at the end of the tableview.

Two multi-line labels

Hi,

I'm faced with this strange issue. I have a prototype UITableViewCell with two UILabels with both of their no. of lines set to 0 and all the necessary constraints are added .

screen shot 2015-04-04 at 7 35 09 pm

Here are the Content hugging and content compression resistance priorities.

  • Top label

screen shot 2015-04-04 at 7 36 03 pm

  • Bottom label

screen shot 2015-04-04 at 7 37 52 pm

And here is the code.

import UIKit

class TableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        configureTableView()
    }

    private func configureTableView() {
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 90
    }

    private func eventCellAtIndexPath(indexPath: NSIndexPath) -> EventCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("EventCell") as EventCell
        cell.nameLabel.text = "(Monrovia) Brennan, Cathleen Andresson Carlsson"
        cell.addressLabel.text = "176 N, Sunset Pl, Monrovia, CA, United States 91016"

        return cell
    }

    // MARK: - Table view data source
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 10
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        return eventCellAtIndexPath(indexPath)
    }
}

Even though their is no auto layout issue, when I run the app this is how the content is displayed.

1

As you can see the first label is getting cropped!

I faced this same issue a few months back and your answer helped me to resolve it. But doing the same here doesn't seem to work.

private func eventCellAtIndexPath(indexPath: NSIndexPath) -> EventCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("EventCell") as EventCell
    cell.nameLabel.text = "(Monrovia) Brennan, Cathleen Andresson Carlsson"
    cell.addressLabel.text = "176 N, Sunset Pl, Monrovia, CA, United States 91016"

    cell.nameLabel.preferredMaxLayoutWidth = CGRectGetWidth(cell.nameLabel.frame)
    cell.addressLabel.preferredMaxLayoutWidth = CGRectGetWidth(cell.addressLabel.frame)
    return cell
}

2

Why do you think this is happening?

I uploaded a demo project to my Dropbox.

Code does not compile

There is an error in code:
TableViewCell.swift:

required init?(coder aDecoder: NSCoder)
{
     super.init(coder: aDecoder)   
     setupViews()
}

TableViewCell.swift:30:14: Failable initializer 'init(coder:)' cannot override a non-failable initializer

Adding a Dynamic UIView as a subview of the TableViewCell

First let me start off by saying thank you for creating this project (and the PureLayout library for that matter).

For the past couple of days I've been trying to tackle this issue I posted on stackoverflow (http://stackoverflow.com/questions/30309150/custom-tableviewcell-with-subview-whose-height-changes)

I started using your TableViewCell project to try and integrate what I'm doing into your code and see if it would work, but alas I'm stilling coming up empty.

In your existing project, I'm trying to add a UIView as a subview of the custom TableViewCell class you created, and I have events that are called on the UIView which would cause it to resize in height (mainly increase). However, I've had no luck with this so far for the past couple of days.

Any help or just pointing me in the proper direction would be greatly appreciated at this point. Here are the changes I made to your code to try and get the subview to work:

screen shot 2015-05-19 at 3 50 34 pm
screen shot 2015-05-19 at 3 51 06 pm
screen shot 2015-05-19 at 3 51 21 pm
screen shot 2015-05-19 at 3 51 36 pm

And here's the app crashing error xCode is giving me:
2015-05-19 15:49:15.778 TableViewCellWithAutoLayout[23816:12789074] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with items <UIView: 0x7fc0fb5668e0; frame = (0 0; 375 667); layer = <CALayer: 0x7fc0fb53a310>> and <UILabel: 0x7fc0fb55db70; frame = (0 0; 0 0); text = 'Marion'; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc0fb55df20>> because they have no common ancestor. Does the constraint reference items in different view hierarchies? That's illegal.'

Jumpy scrolling when rotating device

Has anyone found a solution to the issue (present in the sample project) where if you scroll a bit, rotate the device, then scroll back up the cells are very jumpy and the scrolling seems off?

No auto layout on first load tablewview

I have a problem. I create a TableViewController with dynamic height on the cells. I follow this answer

http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights/18746930#18746930

My problem its that (I copy the exact constraints) when I load information, like 2-3 lines it only appear the first or second line and the other line I need to scroll until the cell its outside the screen and bring it inside again and it comes with the other line. I hop eI explain my self.

I have my code, mostly the same as that post

var cell = tableView.dequeueReusableCellWithIdentifier("CellP", forIndexPath: indexPath) as CellPTableViewCell

        if (indexPath.row+1)%2 == 0 {
            cell.contentView.backgroundColor = UIColor(red: 244/255, green: 244/255, blue: 244/255, alpha: 1.0)
        }

        cell.label1.text = "\(userName) \(userLast)"
        cell.label1.text = userText

        cell.setNeedsUpdateConstraints()
        cell.updateConstraintsIfNeeded()
        return cell

Any ideas? the constraints are exactly the same as the post, I just modify the font (I try with the font he propose and its the same error)

Edit: I try it on iPhone 6 (Physically). and iPhone 4S (Simulator)

Best,

Storyboard/nib example?

Hi
Could you possibly add a storyboard/nib example, because I can not get even the simplest example to work without getting exceptions thrown.

Constraints break when setting kLabelVerticalInsets to 16.0f

When I set the vertical insets to some higher value the contraints of the UITableViewCell break.
Not shure what is causing it.
It seems to be the size of cells content view. But leveraging that size upwards does't lead to a solution.

2016-04-11 14:52:45.832 TableViewCellWithAutoLayout[451:79339] 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. 
(
    "<NSLayoutConstraint:0x17e97900 V:|-(16)-[UILabel:0x17e96600'Thonburi']   (Names: '|':UITableViewCellContentView:0x17d99fc0 )>",
    "<NSLayoutConstraint:0x17da1a80 V:[UILabel:0x17e96600'Thonburi']-(16)-[UILabel:0x17d9b1c0'Lorem ipsum dolor sit ame...']>",
    "<NSLayoutConstraint:0x17da2bc0 UILabel:0x17d9b1c0'Lorem ipsum dolor sit ame...'.bottom == UITableViewCellContentView:0x17d99fc0.bottom - 16>",
    "<NSLayoutConstraint:0x17e96fa0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x17d99fc0(44)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x17da1a80 V:[UILabel:0x17e96600'Thonburi']-(16)-[UILabel:0x17d9b1c0'Lorem ipsum dolor sit ame...']>

Distorted Scrolling on Addition of Item and Upwards Scroll

I've seen this on a few projects and am starting to believe this is an iOS bug. However, if you scroll to the bottom, add a new item, and start scrolling upwards you'll notice that the scroll jumps all over the place.

Steps to reproduce:

  1. Scroll to the bottom
  2. Hit the "+" for a new item
  3. Gently scroll to the top

Table is jumpy when scrolling bottom to top of table

Hi,
I'm working with UITableview for chat application it's working very well in update and insert cell but when scroll the tableview bottom to top tableview cell jerking and no smoothly scrolling.
*Note-> I'm not using storyboard and i've used to custom cells (Objective c)
So Please any solution.
Regards
Do

Using UIWebView with MMMarkdown

I was able to use the PureLayout just fine. But i was hoping if I added a UIWebView as followed:

    [self.webview autoPinEdge: ALEdgeTop toEdge: ALEdgeBottom ofView: self.labelTitle withOffset: 10.0 relation: NSLayoutRelationGreaterThanOrEqual];

    [self.webview autoPinEdgeToSuperviewEdge: ALEdgeLeading withInset: kLabelHorizontalInsets];
    [self.webview autoPinEdgeToSuperviewEdge: ALEdgeTrailing withInset: kLabelHorizontalInsets];
    [self.webview autoPinEdgeToSuperviewEdge: ALEdgeBottom withInset: kLabelVerticalInsets];

Sadly the frame of the web view was always zero.

What if I replace bodyLabel with a button?

I've turned bodyLabel's class UILabel into UIButton(As you can see in pic1 ~ pic3). As you know, UIButton also has its intrinsic content size (just like UILabel). I just want to have the cell's subviews "exert pressure" and make the content view expand to fit them. But the cell height became same and, of course, went wrong(As you can see in pic4 and pic5). Can anybody tell me why and what should I do to solve this problem?
pic1
1

pic2
2

pic3
3

pic4
5

pic5
6

pic6
7

Self sizing issue with 3 UILabels inside a cell

Hi,

I'm kinda stomped by this issue. Its going to be a little lengthy but please bear with me.

This issue came across in an iOS 8 app I'm creating. I've set all the constraints so I'm not getting any auto layout errors or warnings. But when I run it, it looks like this.

rsz_ios_simulator_screen_shot_sep_21_2014_112239_pm

The blue and the black labels are supposed to resize themselves to fit their content thus making the cell's height dynamic. I've set the number of lines of both of those labels to 0 as well.

Here's a weird thing that happens. If I rotate the device to landscape and back to portrait, I get this.

rsz_ios_simulator_screen_shot_sep_21_2014_112247_pm

Now the black label has resized itself to fit all its text but it overflows the cells boundaries. I have set these two lines of code in the viewDidLoad() method.

tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableViewAutomaticDimension

I've uploaded a test Xcode project to Dropbox demonstrating this issue so it'll be easier for you to give it a look. Can you please help me out to resolve this?

Thank you.

EDIT: After I ran into this issue, I came across this tutorial. Although it's on iOS 7, I picked up a few pointers regarding auto layout. So I created a separate project to test them out.

Basically what I did was moved the 3 labels closer to each other so that their vertical spaces would be 0 (I did this because that's how it was done in this tutorial's example project but I noticed in your project, you could have different vertical space values). And added other constraints to the sides. No auto layout errors or warnings again.

When I run it the first time, the black label cropping issue is still there.

rsz_ios_simulator_screen_shot_sep_21_2014_115649_pm

But I turn it to landscape and back again to portrait and..

rsz_ios_simulator_screen_shot_sep_21_2014_115700_pm

all the all the cells are resized properly to fit both labels! Still can't figure out why this doesn't happen in the first run though. I uploaded a separate project to here (This project has 2 cells. One with 3 labels and one with 2 labels. I was just experimenting. The same issue came up in both of these scenarios).

My actual issue is the first one. I just added the second part to show a different approach I took.

If you could take a look. I'd really appreciate it. This issue has me stomped.

Thank you.

TableView jumps

Hello,

When I use this

[m_tableView beginUpdates];
[m_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:m_indexPath] withRowAnimation:UITableViewRowAnimationFade];
[m_tableView endUpdates];

and

[m_tableView beginUpdates];
[m_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:m_indexPath] withRowAnimation:UITableViewRowAnimationFade];
[m_tableView endUpdates];

tableView jumps, it happens because of this

m_tableView.estimatedRowHeight = 97.0;
m_tableView.rowHeight = UITableViewAutomaticDimension;

But then if we remove this, then we will not variable height.

So guys please help me out..

Here is my SO question for same

http://stackoverflow.com/questions/29079485/reloadrowsatindexpath-weird-behaviour-for-uitableview

Regards
Ranjit

Attempting to Display a UIImageView onto your Demo App

I am attempting to Display a UIImageView on the Left of the Title Label, however nothing shows could you lead me in the correct direction?

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [UILabel newAutoLayoutView];
        [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail];
        [self.titleLabel setNumberOfLines:1];
        [self.titleLabel setTextAlignment:NSTextAlignmentLeft];
        [self.titleLabel setTextColor:[UIColor blackColor]];

        self.proImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.proImageView.translatesAutoresizingMaskIntoConstraints = NO;
        self.proImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.proImageView.backgroundColor = [UIColor blackColor];

        self.bodyLabel = [UILabel newAutoLayoutView];
        [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail];
        [self.bodyLabel setNumberOfLines:0];
        [self.bodyLabel setTextAlignment:NSTextAlignmentLeft];
        [self.bodyLabel setTextColor:[UIColor darkGrayColor]];

        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.bodyLabel];
        [self.contentView addSubview:self.proImageView];

        [self updateFonts];
    }

    return self;
}

- (void)updateConstraints
{
    if (!self.didSetupConstraints) {
        // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception.
        // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below.
        //      See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188
        // self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f);

        [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.titleLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];
        [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets];
        [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
        [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];

        [self.proImageView autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.titleLabel withOffset:kLabelHorizontalInsets];
        [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.proImageView autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];
        [self.proImageView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
        [self.proImageView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
        [self.proImageView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];


        [self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets];

        [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.bodyLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];
        [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
        [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
        [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];

        self.didSetupConstraints = YES;
    }

    [super updateConstraints];
}

Looking for help with debugging an autolayout issue

Hi,

I came across this project, and was trying to do something similar, but have run into an issue. I'm still learning Autolayout, so wondering if you'd have the time to help me out with this.

My aim is to create UITableViewCell with a UIImageView that is pinned to the top, left and right of the cell, and has a fixed height, and a variable height UILabel that is pinned to the bottom of the image view, left, right and bottom of the cell. (all with some insets)

So, I created a UITableViewCell subclass that looks like the following

#import "SJTableViewCell.h"
#import "PureLayout.h"

#define kLabelHorizontalInsets      15.0f
#define kLabelVerticalInsets        10.0f

@interface SJTableViewCell ()

@property (nonatomic, assign) BOOL didSetupConstraints;

@end

@implementation SJTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.imgMain = [UIImageView newAutoLayoutView];
        self.imgMain.contentMode = UIViewContentModeScaleAspectFill;
        self.imgMain.clipsToBounds = YES;

        self.lblText = [UILabel newAutoLayoutView];
        [self.lblText setLineBreakMode:NSLineBreakByTruncatingTail];
        [self.lblText setNumberOfLines:0];
        [self.lblText setTextAlignment:NSTextAlignmentLeft];
        self.lblText.backgroundColor = [UIColor clearColor];

        self.contentView.backgroundColor = [UIColor clearColor];

        [self.contentView addSubview:self.lblText];
        [self.contentView addSubview:self.imgMain];
    }

    return self;
}

- (void)updateConstraints
{
    if (!self.didSetupConstraints)
    {
        [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.imgMain autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];
        [self.imgMain autoSetDimension:ALDimensionHeight toSize:200.0f relation:NSLayoutRelationEqual];
        [self.imgMain autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets];
        [self.imgMain autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
        [self.imgMain autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];

        [self.lblText autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.imgMain withOffset:kLabelVerticalInsets];

        [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
            [self.lblText autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
        }];
        [self.lblText autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
        [self.lblText autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
        [self.lblText autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];

        self.didSetupConstraints = YES;
    }

    [super updateConstraints];
}

@end

But, when I run the project on the device, I see the following log

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:0x18956620 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x176d3f20(44)]>",
    "<NSLayoutConstraint:0x18b6b600 V:[UIImageView:0x18fcbee0(200)]>",
    "<NSLayoutConstraint:0x18b6eda0 V:|-(10)-[UIImageView:0x18fcbee0]   (Names: '|':UITableViewCellContentView:0x176d3f20 )>",
    "<NSLayoutConstraint:0x189f1010 V:[UIImageView:0x18fcbee0]-(10)-[UILabel:0x18de9d70'\Ufffc  Xbox, Windows Store no...']>",
    "<NSLayoutConstraint:0x18b7bc30 UILabel:0x18de9d70'\Test Test Test Test Test Tes...'.bottom == UITableViewCellContentView:0x176d3f20.bottom - 10>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x18b6b600 V:[UIImageView:0x18fcbee0(200)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Removing this line

[self.imgMain autoSetDimension:ALDimensionHeight toSize:200.0f relation:NSLayoutRelationEqual];

does make the log go away, but it also makes my image view variable height. I'm not sure how I would go about sorting this. Hope you can help me out.

"fatal error: use of unimplemented initializer" when running

I downloaded the zip, open in freshly updated xcode 6.2 and get this error:

/path-to/TableViewCellWithAutoLayoutiOS8-master/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift: 10: 7: fatal error: use of unimplemented initializer 'init(nibName:bundle:)' for class 'TableViewCellWithAutoLayout.TableViewController'
(lldb)

Integrate support for expanding/collapsing cell

How is it possible to support expand/collapse the multiline label? E.g. The multiline label should show only three lines. If I tap the cell should expand revealing all the content of the multiline label.
Any suggestions?

Thanks,
Lorenzo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.