容器视图中的自定义UITableViewController:NSInternalInconsistencyException

时间:2014-08-20 23:49:33

标签: ios uitableview uistoryboard

我正在尝试在UITableViewController中插入自定义Container View。容器视图放在静态UITableView的单元格内,如下图所示。

enter image description here

我只想要一种方法在同一个屏幕中将静态和动态单元格结合起来。

当字段 Class 为空时(即标准的UITableViewController)Identity Inspector,它在单元格内显示一个空的动态表。但是当我在该字段中放置我的自定义类名(扩展UITableViewController)时,我得到NSInternalInconsistencyException

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

这些是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

我必须承认我仍然不理解Container View背后的所有逻辑,但我只想在内部显示一个视图(不进行任何交换或其他)。

任何帮助将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:1)

将我的头撞在桌子上好几个小时后,我设法解决了这个问题。 我不得不分配/初始化MyCustomUITableViewController的tableview。我重写了MyCustomUITableViewController的loadView方法:

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

很高兴去!

相关问题