1
votes

I'm configuring a UIPickerView inside a static UITableViewCell via the Storyboard. For some reason, the UIPickerView does not appear when loading the Controller.

Storyboard: Storyboard

The UIPickerView is a child of the Cell Content View...and the Table View is configured to display "Static Cells". (Grouped style)

The UIPickerView delegate and dataSource are connected to the UITableViewController as Outlets in the Storyboard Connections Inspector:

Connections Inspector

If I programmatically add the Picker View to the Table Cell, in the viewDidLayoutSubviews callback, then the PickerView appears and the delegate callbacks are fired so that the Picker can be configured with data. (titleForRow, etc):

In the TableViewController.m:

    // Can't figure out why - but regionPicker view can't be added in viewDidLoad, so it gets added here
- (void) viewDidLayoutSubviews {
    // For some reason regionPicker view gets pushed to top of view unless setting x & y to 0,0 here...
    [self.regionPicker setFrame:CGRectMake(0, 0, 320, 162)];
    // Add the regionPicker view as a subview to the regionPickerCell
    [self.regionPickerCell.contentView addSubview:self.regionPicker];    
}

This causes problems with proper initialization of the Picker, because viewDidLayoutSubviews gets called every time a new selection is made in the UIPIckerView.

Here's what my TableViewController.h file looks like:

@import UIKit;

@class DetailViewController;

@interface DetailViewController : UITableViewController<UIPickerViewDataSource, UIPickerViewDelegate>

@property (weak, nonatomic) IBOutlet UITableViewCell *regionCell;
@property (weak, nonatomic) IBOutlet UITableViewCell *regionPickerCell;
@property (weak, nonatomic) IBOutlet UIPickerView *regionPicker;

@end

What's the proper way to load a UIPickerView in a Static UITableViewContoller via the Storyboard?

Also, I don't know if this is relevant, but the Table View Controller, in this case, is getting loaded via a segue, from another UITableViewController:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"configNotification"]) {

        UINavigationController *navigationController = segue.destinationViewController;
        // Here's the UITableViewController in question...
        DetailViewController *detailViewController = [navigationController viewControllers][0];

        NSIndexPath *selectedPath = [self.tableView indexPathForCell:sender];
    }
}

Any thoughts are greatly appreciated!

Xcode v6.1, SDK v8.1

1
Have you checked the reuseIdentifiers for the cells?n00bProgrammer
What is the height of the table view cell? And check that you are setting the values proper or not.Yogesh Suthar
@UtkarshSingh - I'm not using the reuseIdentifier...these cells are static.Sly
@YogeshSuthar - the containing cell is set to be 164px high from the Size Inspector, in the Storyboard. I'm pretty sure that when the view loads that the height is not 0. Also, from the debugger, when in viewDidLoad, I can do a po self.regionPickerCell.contentView.subviews and I see that there aren't any subviews. (empty array) After I programmatically add the UIPIckerView in viewDidLayoutSubviews the Picker does appear inside the designated cell.Sly

1 Answers

0
votes

I resolved this by deleting the existing picker views in this controller, from the Storyboard, and then adding each one back.

For some reason, the Picker View was greyed out in the Storyboard view. (first picture above) After deleting the Picker View and adding it back it was not greyed out. I don't know why the Picker View was greyed out in the first place, or what that signifies from the Storyboard, but hopefully this will help someone in the future.