0

So, the app I'm making has a home screen where we can add widgets, and the widgets are displayed in a table view using some custom cells that are "foldable". And we're loading all the cells programmatically with views created in a different story board. So that way everything is modular.

I'm having an issue with getting the view to display correctly with auto layout. The weather should be centered, but it isn't. I've checked in the preview of the weather widget in the IB and it is centered, but it isn't being centered in the table cell.

Here is code, this is in cell for row at index path. Since it is a special cell I'm using from an external library, there is a small view to the cell and a big view. Currently, I'm focusing on the big view first. Also note: Inside of the table view cells I have added a view underneath the bar. That's what bigView and smallView are. A

let storyboard = UIStoryboard.init(name: "\(self.widgets[indexPath.row])Widget", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("\(self.widgets[indexPath.row])Widget")
let smallController = storyboard.instantiateViewControllerWithIdentifier("\(self.widgets[indexPath.row])WidgetSmall")

self.addChildViewController(controller)
self.addChildViewController(smallController)

cell.bigView.addSubview(controller.view)
cell.smallView.addSubview(smallController.view)

controller.didMoveToParentViewController(self)
smallController.didMoveToParentViewController(self)
return cell

View to be loaded at home screen
Home screen where view is loaded

jped
  • 153
  • 1
  • 12
  • Add the code how are you adding widget in your cell, it is something there. – iphonic Jun 27 '16 at 17:57
  • @iphonic Ok, I have added code. – jped Jun 27 '16 at 20:59
  • Your code doesn't have information for the frame in which you are adding the widget, plus you need to add constraint programatically to the widget with respect to the parent view to allow it to adjust accordingly.. See my answer [how to add constraint](http://stackoverflow.com/a/31651348/790842) you need to do exactly same except instead of height constraint you need to add bottom constraint, it will work for you. – iphonic Jun 28 '16 at 06:03
  • @iphonic do I need to add the trailing and leading constraints as well? – jped Jun 28 '16 at 15:49
  • @iphonic Nvm, I got it to work!! Thanks!!! – jped Jun 28 '16 at 16:06

0 Answers0