所以基本上我有一个问题,我以前从未使用过 Storyboard ,这让我很沮丧,但我正在努力学习它。我有多个导航 Controller ,我将它们全部嵌入到一个选项卡栏 Controller 中。 (见图1)![图1][1]
但是,我无法获取任何类型的数据来填充 cell.textLabel.text
我确信这很容易解决,但就像我说的,我是 Storyboard的新手。
我的代码在下面,但首先是我在 Storyboard 中设置的:
TabBarController 设置为初始 View Controller 。 类设置为默认值。所有尺寸都设置为推断。 触发的 Segues 设置为所有 4 个导航 Controller
对于我的 Publications Navigation Controller (第一个我试图填充数据的 Controller ),我将类设置为默认值。 触发的 Segues 被设置为 Root View Controller ,在这种情况下是标题 Root View Controller 将 Segues 呈现为标签栏 Controller 的关系
该导航 Controller 的 Root View Controller 我将类设置为“PublicationsTableViewController” TableView 内容设置为动态原型(prototype) 网点: dataSource 是 Root View Controller (它所在的那个) 委托(delegate)是 Root View Controller (它所在的那个)
表格 View 单元格 还没有 outlets 或 segues 风格是定制的 重用标识符是“Cell”
在 PublicationsTableViewController 中我的代码是:
.h
@interface PublicationsTableViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSArray *mainpubArray
.m
@interface PublicationsTableViewController ()
@end
@implementation PublicationsTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"PUBLICATIONS";
_mainpubArray = @[@"Animals", @"Buildings", @"Vehicles", @"Entertainment"];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_mainpubArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [_mainpubArray objectAtIndex:indexPath.row];
return cell;
}
![在此处输入图片描述][2]
如有任何帮助,我们将不胜感激。
最佳答案
您将返回 0 作为部分数...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 0;
}
应该是……
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1; //Or how many sections you need
}
关于ios - UITableView 单元格标题不填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26859764/