容器视图中的自定义 UITableViewController

Custom UITableViewController inside Container View

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

http://i.stack.imgur.com/A762B.png

我只是想要一种在同一屏幕中将静态单元格与动态单元格组合在一起的方法。

在身份检查器中,当字段 Class 为空(即标准 UITableViewController)时,它会在单元格内显示一个空的动态 table。但是当我在那个字段中放置我的自定义 class 名称(扩展 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:您不能在另一个控制器中放置一个控制器。这意味着,在您的静态 table 视图中,您不能拥有动态 table 视图控制器。

解决方案1:You 可以有一个动态的Table视图。

问题 2:视图控制器中不能有静态 Table视图。如果您想要静态 Table 视图,则需要 UITableViewController 而不是 UIViewController。

解决方案 2:您只需要删除现有的 ViewController 并替换为 UITableViewController.

现在要实现一个控制器,其中您可以在静态 Table 视图中包含动态 table 视图,您需要在静态 table 视图中实现动态 table 的数据源Table 的 ViewController 这将是一个非常糟糕的做法。 静态 table 不需要知道关于动态 Table 的任何信息,至少不需要知道将填充到动态 table 中的数据。但是,如果您想要在静态 tableView 中使用动态 tableView,那么静态 tableView 的控制器需要实现 UITableViewDatasource。

所以,你可能要重新考虑结构。