![](/img/trans.png)
[英]Custom UITableViewController inside Container View: NSInternalInconsistencyException
[英]Custom UITableViewController inside Container View
我试图在容器视图内插入自定义UITableViewController。 容器视图放置在静态UITableView的单元格内,如下图所示。
http://i.stack.imgur.com/A762B.png
我只想要一种在同一屏幕中将静态单元与动态单元组合的方法。
在身份检查器中,当“类”字段为空(即标准UITableViewController)时,它将在单元格内部显示一个空的动态表。 但是,当我在该字段中输入自定义类名称(扩展了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:另一个控制器中不能有一个控制器。 这意味着,在静态表视图中,不能有动态表视图Controller。
解决方案1:您可以具有动态TableView。
问题2:视图控制器内部不能有静态Tableview。 如果要使用静态Tableview,则需要有一个UITableViewController而不是UIViewController。
解决方案2:您只需要删除现有的ViewController并替换为UITableViewController。
现在要实现一个控制器,可以在静态表视图中拥有动态TableView,则需要在静态表的ViewController中实现动态表的数据源,这将是非常糟糕的做法。 静态表不需要了解有关动态表的任何信息,至少不需要了解将在动态表中填充的数据。 但是,如果要在静态tableView中使用动态tableview,则静态tableview的控制器需要实现UITableViewDatasource。
因此,您可能需要重新考虑结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.