Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法使用.xib文件在自定义单元格中添加任何内容?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 无法使用.xib文件在自定义单元格中添加任何内容?

Ios 无法使用.xib文件在自定义单元格中添加任何内容?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我无法从自定义单元格的xib文件中获取内容,单元格为空,cell.xib文件仅包含UILabel,则主类(在主详细信息项目中)中的代码如下所示: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = (MyCell*)[tableView dequeueReusableCellWithIdentifier:@"C

我无法从自定义单元格的xib文件中获取内容,单元格为空,cell.xib文件仅包含UILabel,则主类(在主详细信息项目中)中的代码如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = (MyCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//[self configureCell:cell atIndexPath:indexPath];
return cell;
}

当self-configureCell用于核心数据时,为了测试我的UILabel,我不想从核心数据中获取值,所以我对这行进行了注释。 在情节提要中,“自定义类”被设置为“MyCell”,标识符是相同的

我在班上也试过这个,迈塞尔:

- (void)awakeFromNib {
// Initialization code
self.ibLabel.text = @"allo";
}
但是我的手机还是空的。。。.xib中每个单元格的高度也与代码中的相同


编辑#1:

这有助于注册单元格自定义类:

UINib *cellNib = [UINib nibWithNibName:@"MyCell" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"Cell"];

为什么不在牢房里试一试呢

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath {
  MyCell *cell = (MyCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell"  forIndexPath:indexPath];
  cell.ibLabel.text = @"allo";
  return cell;
如果这不起作用,您必须确保“Cell”也是故事板中的标识符,并且在故事板中,类是myell

首先,一个愚蠢的问题:你实现了这个方法并且它没有返回0吗

 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 return 5; // To test
 }
第二:
在Storyboard中,更改自定义单元格的背景颜色,以确保这是单元格绘制。

您必须初始化单元格。这可能是第一个细胞,你以前没有过

如果现有单元格可用,此方法将其出列,或者基于您以前注册的类或nib文件创建一个新单元格


确保在viewDidLoad中注册nib:

    self.tableView.registerNib(UINib(nibName: "MyCell", bundle: nil), forCellReuseIdentifier: "Cell")

谢谢,但还是没什么。。。该类实际上是“MyCell”和标识符“Cell”,核心数据不再填充单元格,而我的Cell类是一个带有.xib文件的基本类。。。就这些了。@Paul还有更多的东西要测试。非常感谢Onik IV的帮助,答案是使用registerNib,现在手机显示良好,感谢您的支持!;)谢谢,还是没什么。。。我删除了tableView,添加了一个新的,插座似乎是自动添加的(数据和委托设置为“主”),我还要求1行和1节,但仍然有大量的空行,这正常吗?你说的“主”是什么意思?您必须将委托和数据源链接到tableView的文件所有者,并且必须将其声明为UITableViewDelegate和uitableViewDataSource Hanks LucaD,现在工作正常,我必须注册nib名称,请参见下面的答案,非常感谢您的支持!;)是的,谢谢,如果nib与类名称相同,为什么我们必须注册它?它现在可以正常工作了,多亏了一点,看起来这只是苹果公司需要的接线过程的一部分。很高兴它对你有用。
    self.tableView.registerNib(UINib(nibName: "MyCell", bundle: nil), forCellReuseIdentifier: "Cell")