Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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/22.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 无法设置自定义表视图单元格的属性_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 无法设置自定义表视图单元格的属性

Ios 无法设置自定义表视图单元格的属性,ios,objective-c,uitableview,Ios,Objective C,Uitableview,在自定义单元格上设置视图元素时遇到问题。表格单元格显示在“我的表格视图”中,但未设置属性,因此仅显示空/空白单元格 tableView不是tableView控制器,而是viewController中的tableView 我有以下文件: CustomCell.xib: 在这里,我使用IB通过使用对象库中带有标签和图像的表视图单元格来构建自定义单元格。我将标识符设置为orderListCell。在这个屏幕上,我按住ctrl键并拖动以在customCell.h中创建插座 CustomCell.h 在这

在自定义单元格上设置视图元素时遇到问题。表格单元格显示在“我的表格视图”中,但未设置属性,因此仅显示空/空白单元格

tableView不是tableView控制器,而是viewController中的tableView

我有以下文件:

CustomCell.xib:
在这里,我使用IB通过使用对象库中带有标签和图像的表视图单元格来构建自定义单元格。我将标识符设置为orderListCell。在这个屏幕上,我按住ctrl键并拖动以在customCell.h中创建插座

CustomCell.h
在这里,我看到我的所有iboutlet都是上述文件中的属性

CustomCell.m
我就这样离开了

OrderListViewController.h
这里我导入customCell.h并使用协议UITableViewDelegate、UITableViewDataSource

OrderListViewController.m
在这里,我将tableView委托和tableView数据源设置为self。我还从故事板为我的tableView创建了一个IBOutlet

我使用以下代码尝试显示我的单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath      *)indexPath
{

static NSString *cellIdentifier = @"orderListCell";

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (!cell) {
    cell = [[CustomCell  alloc] init];
}

 cell.myLabel.text = @"aaaaaaaa"; //[[self.orders objectAtIndex:indexPath.row] objectForKey: @"tableNo"];



return cell;
}
我简化了我的代码,以证明即使将标签设置为简单字符串(@“aaaaaa”)也不起作用。当我查看调试器中的对象时,该单元格确实具有IBOutlets中的所有属性,并且该单元格确实出现在我的tableView中,只是label.text=xxx似乎不起作用

我看过以下帖子,但要么不理解,要么不适合我:





任何帮助或建议将不胜感激

cell=[[CustomCell alloc]init]不会从XIB创建单元格,因此不会创建任何XIB内容

使用
registernb:forCellReuseIdentifier:
在表视图中注册XIB,以便它为您创建单元格实例(您不需要自己在
cellForRowAtIndexPath
中创建实例)


如果您不想这样做,您可以显式地使用
nibWithNibName:bundle:
instanceWithOwner:options:
,加载NIB,然后从返回的视图列表中获取单元格实例(该视图应仅包含1项)。

哇,这个问题真的让我感到沮丧。你的回答让我走上了正确的道路,经过一些研究和尝试,我终于找到了答案。在使用registerNib:forCellReuseIdentifier之前:首先需要使用[UINib nibWithNibName:@“MyCustomCellName”bundle:nil]创建nib,然后在前面提到的方法中使用它。非常感谢!