在我的 storyboard
上,我有一个 ViewController
,我想添加一个包含 1 个部分和 2 个静态单元格的 UITableView
。这就是我现在所做的一切,但在编译时出现此错误。
Static table views are only valid when embedded in UITableViewController instances
我错过了什么?
最佳答案
看This question .基本上是一样的。
还有什么问题,尽管问! :)
编辑的东西:
UITableViewController *controller = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.view addSubview:controller.tableView];
然后您需要做的就是在头文件中添加 UITableViewDataSource 并且您需要数据源方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if([indexPath row] = 0){
do something
}else if([indexPath row] = 1){
do something else
}
关于objective-c - 将 UITableView 添加到 Storyboard上的 ViewController 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14168157/