Not able to add static UITableViewCell into tableview

Bha*_*Dev 7 objective-c uitableview ios

由于我是 IOS 开发的新手,我正在尝试添加CustomeCelltableView,但无法从库中添加它。

我所做的只是拖动TableView我的ViewController单元格,而不是拖动tableview其中的单元格,但它作为额外视图添加到 的ViewController视图下,无法将其添加到表格视图中。

我被困在这里,不知道如何通过拖放添加单元格。

截屏 :

我知道如何通过编码添加单元格,但通过代码添加所有内容的过程非常漫长。

任何指导将不胜感激。

提前致谢。在此输入图像描述在此输入图像描述

Cod*_*ger 4

根据我的经验,TableView当您使用或编辑ViewController/View/Cell时,您不能将自定义单元添加到XIB.

为此,你有 2 个选择

第一:使用 Storyboard 来设计你的TableViewCell.

第二:创建一个新的自定义单元格并将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];
}
Run Code Online (Sandbox Code Playgroud)

希望这有助于将单元格添加到 XIB 中。