【发布时间】:2018-01-01 11:46:14
【问题描述】:
我将 tableView 作为 UIViewController 的子视图,在情节提要中,我将原型单元格添加到该场景中。但似乎情节提要中的单元格设计不起作用,原型单元格似乎仅适用于 UITableViewController?
这是我的故事板设计,我使用 tableView 作为 ViewController 的子视图,并在其中添加两个原型单元格(粉色和蓝色单元格)
这是我的 tableView 代码:
@implementation SubViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:@"TableViewCell"];
[self.tableView registerClass:[ATableViewCell class] forCellReuseIdentifier:@"ATableViewCell"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
TableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];
return cell;
}
else
{
ATableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ATableViewCell" forIndexPath:indexPath];
return cell;
}
}
当我运行我的代码时,我希望会有一个蓝色和粉红色的单元格,但实际上,tableView 只会有两个空白单元格(似乎故事板中的设计不起作用)
【问题讨论】:
-
您遇到的错误是什么。你能添加一些代码。如果您正确设置了源和委托,它应该可以工作。
-
@kapsym thx,我刚刚发布了我的故事板设计和代码,有什么问题吗?
-
您能描述一下您期望发生的事情,和实际发生的事情吗?在这种情况下,“不起作用”是什么意思?
-
[self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:@"TableViewCell"]; [self.tableView registerClass:[ATableViewCell 类] forCellReuseIdentifier:@"ATableViewCell"];在情节提要的原型单元中不需要。
标签: ios xcode storyboard xib