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

Can't load table view contains on UIViewController #88

Closed
mrjimoy opened this issue Jan 9, 2017 · 6 comments
Closed

Can't load table view contains on UIViewController #88

mrjimoy opened this issue Jan 9, 2017 · 6 comments

Comments

@mrjimoy
Copy link

mrjimoy commented Jan 9, 2017

Hi, is it possible to load a view controller that contains a table view as a pop-up? I tried to load it but the table view doesn't get rendered. I am not attaching any code here. Please confirm. Thanks.

Best regards,
Jimmy

  • Mac OS version (e.g. 10.12): 10.12
  • Xcode version (e.g. 8.0): 8.1
  • PopupDialog version (e.g. 0.5.0): 0.5
  • Minimum deployment target (e.g. 9.0): 8.0
  • Language (Objective-C / Swift): Swift
  • In case of Swift - Version (e.g. 3.0): 3.0
@mwfire
Copy link
Member

mwfire commented Jan 9, 2017

Hi @mrjimoy,

I am not sure if I understood you correctly, but did you have a look at the example provided in #87? This is an example of a custom view containing a table view used with PopupDialog. It is not using Storyboard or XIBs, however the RatingDialog in the very example of the PopupDialog repo is using a custom view controller with XIBs.

With table views and any kind of scroll views, you have to set a fixed height on them. Always make sure the constraints are satisfied.

Cheers
Martin

@mrjimoy
Copy link
Author

mrjimoy commented Jan 10, 2017

Hi @mwfire,

Thanks for your reply.

I mean I tried to show a custom UIViewController that contains UITableView, but the UITableView didn't showed up on the page. Please see code/images below for more details (I omit some code to simplify).

This is the UIViewController that need to be loaded on the page as a pop-up:
snip20170110_1

And this is what I get (only show the button part which is under UIViewController) :
snip20170110_2

This is the code to show the pop-up:

- (void)showPopup {
    
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"StoryBoard" bundle:nil];
    FormViewController *viewController = (FormViewController *) [storyBoard instantiateViewControllerWithIdentifier:@"CodeForm"];
//    viewController.modalPresentationStyle = UIModalPresentationCustom;

    PopupDialog *popup = [[PopupDialog alloc] initWithViewController:viewController
                                                     buttonAlignment:UILayoutConstraintAxisHorizontal
                                                     transitionStyle:PopupDialogTransitionStyleBounceUp
                                                    gestureDismissal:YES
                                                          completion:^{
                                                              // What to do when the popup closed
                                                              
                                                              
                                                          }];
    
    [self presentViewController:popup animated:YES completion:nil];
    
}

And this is the custom UIViewController's code:

@objc class FormViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    
    @IBOutlet weak var sendVerifyCodeButton: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Hide navigation bar
        navigationController?.isNavigationBarHidden = true
        
        // UITableView properties
        let identifier = NSStringFromClass(UITableViewCell.self)
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: identifier)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.tableFooterView = UIView.init(frame: CGRect.zero)
        tableView.tableFooterView!.isHidden = true
    }

}

extension FormViewController: UITableViewDataSource {
    
    // MARK: - Table view data source
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 9
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        return UITableViewCell()
    }
    
    
    // MARK: - Appearance
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }    
}

I have set the constraint properly but still. Do I miss something?

Thanks.

@mrjimoy mrjimoy closed this as completed Jan 10, 2017
@mrjimoy mrjimoy reopened this Jan 10, 2017
@mrjimoy
Copy link
Author

mrjimoy commented Jan 10, 2017

Btw I tried to set the height of tableview on the storyboard, and it work. When I tried to set the height of the tableview programatically under viewDidAppear's method, it doesn't work..

@mwfire
Copy link
Member

mwfire commented Jan 10, 2017

@mrjimoy, when programatically setting constraints of a view controller that has a storyboard or XIB related view, make sure to also set the translatesAutoresizingMaskIntoConstraints property of the corresponding view to false upfront.

@mwfire mwfire closed this as completed Jan 10, 2017
@mrjimoy
Copy link
Author

mrjimoy commented Jan 10, 2017

@mwfire cool, it works :) thanks..

@andr-ggn
Copy link

andr-ggn commented Jan 10, 2017

@mwfire And how to do if I want add navigation controller into popup? Please, can you help me?

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