简体   繁体   中英

Custom UITableViewController inside Container View: NSInternalInconsistencyException

I am trying to insert a custom UITableViewController inside a Container View . The Container View is placed inside a cell of a static UITableView as shown in the figure below.

在此处输入图片说明

I simply want a method to combine static with dynamic cells in the same screen.

In the Identity Inspector when the field Class is empty (ie a standard UITableViewController) it works showing an empty dynamic table inside the cell. But when I put my custom class name (that extends UITableViewController) in that field I get a NSInternalInconsistencyException :

[UITableViewController loadView] loaded the "Enx-aT-Rum-view-zY2-9U-Z6d" nib but didn't get a UITableView.

These are the contents of MyCustomUITableViewController:

@implementation MyCustomUITableViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
@end

I have to admit that I still don't understand all the logic behind Container View, but I just want to show only one view inside (not doing any swapping or else).

Any help would be appreciated, thanks!

After banging my head on the desk for so many hours I managed to resolve this. I had to alloc/init the tableview of MyCustomUITableViewController. I override the loadView method of MyCustomUITableViewController:

- (void) loadView{
    self.tableView = [[UITableView alloc]init];
}

And it is good to go!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM