objective-c - 将 UITableView 添加到 Storyboard上的 ViewController 时出错

标签 objective-c ios uitableview

在我的 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/

相关文章:

iphone - 具有直角的 UITableViewStyleGrouped

ios - 在 TableView 中显示搜索结果时没有结果 - swift

ios - 从数组中的数组访问对象(在模型类中定义)

ios - Swift - 保存核心数据后更新 Tableview

html - UIWebview:如何在 html 链接之前放置一个图标并在点击时突出显示

objective-c - 将 App delegate 设置为第一响应者

javascript - phonegap 中的文件选择器支持 ios 和 Android

objective-c - 在 NSPrintInfo 中设置 InputSlot

Objective-C 编码指南

ios - 如何使用 heightForRowAtIndexPath 方法?