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

Constraint-based custom cells somehow don't work. #87

Closed
sxross opened this issue May 28, 2013 · 2 comments
Closed

Constraint-based custom cells somehow don't work. #87

sxross opened this issue May 28, 2013 · 2 comments

Comments

@sxross
Copy link
Contributor

sxross commented May 28, 2013

Either that, or I'm not getting how they're supposed to work. Here's a small extracted project that illustrates the problem. There should be 3 labels per cell, stacked vertically inside a small padding view. Nothing specified in the layout blocks seems to have a rectangle with non-zero size.

https://github.com/sxross/constraint_based_table_cell

@colinta
Copy link
Owner

colinta commented Jun 28, 2013

I think I was able to get this working:

tableview

(on iOS7, so there's that silly status bar)

Here's how I did it:

diff --git a/app/app_delegate.rb b/app/app_delegate.rb
index 36ec472..11d77f6 100644
--- a/app/app_delegate.rb
+++ b/app/app_delegate.rb
@@ -36,9 +36,15 @@ class TableViewController < UITableViewController
         cell.attendees_label = subview(UILabel, :cell_attendees_label, :text => "attendees #{indexPath.row}")
       end
     end
-    cell.contentView.apply_constraints
+
     cell
   end
+
+  def tableView(tableView, willDisplayCell:cell, forRowAtIndexPath:indexPath)
+    cell.restyle!
+    cell.apply_constraints
+  end
+
 end

 class CustomCell < UITableViewCell

Unfortunately, this requires a change to the delegate, not something I can inject automatically. But you win some you lose some. My thinking is that this could be integrated easily:

class TableViewController < UITableViewController
  module Teacup::TableViewDelegate
  # ...
end

Would define tableView(tableView, willDisplayCell:cell, forRowAtIndexPath:indexPath). If you need to define that method yourself, you can call super there.

class TableViewController < UITableViewController
  module Teacup::TableViewDelegate

  def tableView(tableView, willDisplayCell:cell, forRowAtIndexPath:indexPath)
    super
    # stuff
  end

  # ...
end

This is working in this branch: https://github.com/rubymotion/teacup/tree/tablecell

@sxross
Copy link
Contributor Author

sxross commented Jun 28, 2013

Thanks for tracking this down. I've been up to my eyes in a Rails project for one of my best clients and MotionModel is really getting a lot of uptake and hence feature requests, issues, etc. which take time. Maybe I can get back to my iOS app one day :)

Steve

On Jun 28, 2013, at 8:40 AM, "Colin T.A. Gray" notifications@github.com wrote:

I think I was able to get this working:

(on iOS7, so there's that silly status bar)

Here's how I did it:

diff --git a/app/app_delegate.rb b/app/app_delegate.rb
index 36ec472..11d77f6 100644
--- a/app/app_delegate.rb
+++ b/app/app_delegate.rb
@@ -36,9 +36,15 @@ class TableViewController < UITableViewController
cell.attendees_label = subview(UILabel, :cell_attendees_label, :text => "attendees #{indexPath.row}")
end
end

  • cell.contentView.apply_constraints

cell
end
+

  • def tableView(tableView, willDisplayCell:cell, forRowAtIndexPath:indexPath)
  • cell.restyle!
  • cell.apply_constraints
  • end

end

class CustomCell < UITableViewCell
Unfortunately, this requires a change to the delegate, not something I can inject automatically. But you win some you lose some. My thinking is that this could be integrated easily:

class TableViewController < UITableViewController
module Teacup::TableViewDelegate

...

end
Would define tableView(tableView, willDisplayCell:cell, forRowAtIndexPath:indexPath). If you need to define that method yourself, you can call super there.

class TableViewController < UITableViewController
module Teacup::TableViewDelegate

def tableView(tableView, willDisplayCell:cell, forRowAtIndexPath:indexPath)
super
# stuff
end

...

end
This is working in this branch: https://github.com/rubymotion/teacup/tree/tableview


Reply to this email directly or view it on GitHub.

@colinta colinta closed this as completed Jul 29, 2013
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

2 participants