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

Any option to mount the tableview to a UIView? #17

Closed
EdmundLeex opened this issue Jun 10, 2018 · 7 comments
Closed

Any option to mount the tableview to a UIView? #17

EdmundLeex opened this issue Jun 10, 2018 · 7 comments

Comments

@EdmundLeex
Copy link

EdmundLeex commented Jun 10, 2018

If I want to place the table view at a specific spot, how can I do that?

I currently kinda just hack it by adding a parentView open var in QuickTableViewController. Then I have the option to set the parentView.

// viewDidLoad
parentView = parentView ?? view
parentView?.addSubview(tableView)

Does this library already provide a way to do it that I just didn't know?

@bcylin
Copy link
Owner

bcylin commented Jun 10, 2018

I think an easier way to do this is to embed the QuickTableViewController inside another view controller:

class ParentViewController: UIViewController {

  private lazy var childViewController: QuickTableViewController = QuickTableViewController()

  override func viewDidLoad() {
    super.viewDidLoad()
    childViewController.tableView.frame = // set the frame to a specific spot
    view.addSubview(childViewController.tableView)

    // Other container view controller management, such as:
    // addChildViewController(childViewController)
    // childViewController.didMove(toParentViewController: self)
  }

}

@EdmundLeex
Copy link
Author

This should work. Thanks.
But I feel like it might be a better api if it can be easily mounted as a child to any view.

@bcylin
Copy link
Owner

bcylin commented Jun 11, 2018

Thanks for your feedback. Do you have any thoughts on how this API would look like?

@EdmundLeex
Copy link
Author

What do you think about something like this

override func viewDidLoad() {
  super.viewDidLoad()
  self.parentView = uiView
  self.setupTableView()
}

I am doing something quite similar. And it's quite easy to reason about. The only change would just be moving the setup logic out of viewDidLoad, and adding a parentView public var. Let me know what you think. Happy to put together a PR.

@bcylin
Copy link
Owner

bcylin commented Jun 12, 2018

This is also a nice way to achieve what you need. The tableView is already a subview of a parent view, which is the controller.view. I think it's possible to do so without any modification:

class YourViewControlller: QuickTableViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    // the tableView is a subview of self.view
    tableView.frame = // a specific spot
  }

}

@EdmundLeex
Copy link
Author

I can try this out. As a beginner hacking things together, I am using a storyboard. That's why the view way is easy for me.

@EdmundLeex
Copy link
Author

@bcylin that works great. Thanks!

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