无法将静态 UITableViewCell 添加到表视图中
Not able to add static UITableViewCell into tableview
由于我是 IOS 开发的新手,我正在尝试将 CustomeCell
添加到 tableView
中,但我无法从库中添加它。
我所做的只是将 TableView
拖到我的 ViewController
中,而不是将 tableview
单元格拖入其中,但它作为额外视图添加到 ViewController
的视图下无法将其添加到表视图中。
我不知道如何通过拖放添加单元格。
屏幕截图:
我知道如何通过编码添加单元格,但是通过代码添加所有内容的过程非常冗长。
任何指导将不胜感激。
提前致谢。
首先 select 您的 TableView 和 Inspector Window 将 Prototype Cells 增加 1,如屏幕截图所示
根据我的经验,在使用或将 ViewController/View/Cell 编辑到 XIB
时,您不能将自定义单元格添加到 TableView
.
为此你有 2 个选择
1st: 使用 Storyboard 设计你的 TableViewCell
.
2nd: 使用 XIB
创建一个新的自定义单元格并将其加载到您的 tableView
中,名称为 NIB
,如下所示。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
希望这有助于将细胞添加到 XIB 中。
很抱歉回答晚了,如果您使用的是 xib 布局,请检查这个;
由于我是 IOS 开发的新手,我正在尝试将 CustomeCell
添加到 tableView
中,但我无法从库中添加它。
我所做的只是将 TableView
拖到我的 ViewController
中,而不是将 tableview
单元格拖入其中,但它作为额外视图添加到 ViewController
的视图下无法将其添加到表视图中。
我不知道如何通过拖放添加单元格。
屏幕截图:
我知道如何通过编码添加单元格,但是通过代码添加所有内容的过程非常冗长。
任何指导将不胜感激。
提前致谢。
首先 select 您的 TableView 和 Inspector Window 将 Prototype Cells 增加 1,如屏幕截图所示
根据我的经验,在使用或将 ViewController/View/Cell 编辑到 XIB
时,您不能将自定义单元格添加到 TableView
.
为此你有 2 个选择
1st: 使用 Storyboard 设计你的 TableViewCell
.
2nd: 使用 XIB
创建一个新的自定义单元格并将其加载到您的 tableView
中,名称为 NIB
,如下所示。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
希望这有助于将细胞添加到 XIB 中。
很抱歉回答晚了,如果您使用的是 xib 布局,请检查这个;