无法将静态UITableViewCell添加到tableview中
由于我是IOS开发的新手,我正在尝试将CustomeCell
添加到tableView
但我无法从库中添加它。
我正在做的只是在我的ViewController
拖动TableView
而不是在其中拖动tableview
单元格,但是在ViewController
视图下添加它作为额外视图无法将其添加到tableview中。
我被困在这里任何想法如何通过拖放添加单元格。
截屏:
我知道如何通过编码添加单元格,但是通过代码添加每个东西的过程非常漫长。
任何指导将不胜感激。
提前致谢。
根据我的经验,当您使用或编辑ViewController / View / Cell到XIB
无法将Custom Cell添加到TableView
。
为此你有2个选择
1st:使用Storyboard设计TableViewCell
。
第二步:使用XIB
创建新的自定义单元格并将其加载到带有NIB
名称的tableView
,如下所示。
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布局检查这个;
无法在xib文件中向UITableView添加PrototypeCell
为此,首先选择TableView,然后在Inspector窗口中将Prototype Cells增加1,如ScreenShot所示