2016-04-29 79 views
1

我是iOS新手,我正在学习使用storyboard来设计UI。iOS - 为什么table view不显示?

我还没有写任何代码,因为现在所做的所有事情都在故事板中。

该程序是一个Tabbed Application,我用UITableView替换了第一个视图,并将它分配到初始视图控制器。

的整体结构是这样的:

enter image description here

但是,当我在模拟器中运行它,表视图显示没有任何内容(我有几个表视图细胞,你可以在看第一张照片)。

enter image description here

我不能想出什么是错的?

+0

添加委托方法泰伯维 –

+0

这是初学者HTTP一个很好的教程://www.appcoda。 com/ios-programming-tutorial-create-a-simple-table-view-app/ –

+0

查看我的回答@ penguin-penpen –

回答

1

除非你写一些代码,这将是很难看到这些细胞

首先,从拖一的tableView插座各自的viewController并命名的tableView。

要做到这一点,选择在你的故事板自定义TableViewClass,这将允许您将插座拖到类文件 enter image description here

则:

class TableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {...} 

通过实施符合这两个协议既

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

另外不要忘记添加

self.tableView.dataSource = self; 
self.tableView.delegate = self; 

viewDidLoad中()方法

+0

I cr发送了一个'TableViewController',并在'ViewDidLoad()'方法中添加了代码,但它没有效果?如何将课程链接到我的故事板中的表格视图? –

+0

看到我的编辑,我展示了所有需要的步骤 – DCDC

+0

那是'swift'代码吗? –

0

ViewDidLoad或通过故事板添加数据源和委托给自己内部它适合你

- (void)viewDidLoad 
{ 
yourtablename.delegate = self; 
yourtablename.datasource = self; 
} 
1

选择故事板中的tableview并添加像这样的委托方法。

选项A:

//.h file 
@interface Tableviewcontroller : UIViewController< UITableViewDataSource, UITableViewDelegate> 

//.M file 
    - (void)viewDidLoad 
    { 
    yourtablename.delegate = self; 
    yourtablename.datasource = self; 
    } 

选项B:

enter image description here

+0

解决方案B不适合我。但解决方案A确实有帮助! –

+0

好的。那么不要担心享受解决方案.. :) –

相关问题