Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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的自定义UITableViewCell_Ios_Objective C_Uitableview_Xib - Fatal编程技术网

Ios 使用xib的自定义UITableViewCell

Ios 使用xib的自定义UITableViewCell,ios,objective-c,uitableview,xib,Ios,Objective C,Uitableview,Xib,我有一个自定义UITableViewCell,它链接到UITableViewCell xib。当我运行应用程序时,我得到一个错误 我做了很多搜索,找到了一个。当我尝试从“单元格”视图拖动到文件所有者时,该视图似乎不可单击或拖动 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [ta

我有一个自定义UITableViewCell,它链接到UITableViewCell xib。当我运行应用程序时,我得到一个错误

我做了很多搜索,找到了一个。当我尝试从“单元格”视图拖动到文件所有者时,该视图似乎不可单击或拖动

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategorieUITableVIewCell"];
    if (cell == nil) {
        UIViewController *tempVC = [[UIViewController alloc] initWithNibName:@"CategorieUITableVIewCell" bundle:nil];
        cell = (CategorieUITableVIewCell *)tempVC.view;
    }

    return cell;
}




Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "CategorieUITableVIewCell" nib but the view outlet was not set.'

不确定这是否足够清楚,但如果您有任何问题,请询问。

请检查标识符是否与您在xib中指定的标识符匹配。然后把你的头发换掉

if (cell == nil) {
    UIViewController *tempVC = [[UIViewController alloc] initWithNibName:@"CategorieUITableVIewCell" bundle:nil];
    cell = (CategorieUITableVIewCell *)tempVC.view;
}
编码到

if (cell == nil) {
    cell = [[[NSBundle mainBundle] loadNibNamed:@"CategorieUITableVIewCell" owner:nil options:nil] objectAtIndex:0];
}

这肯定会奏效。您可以在cellForRowAtIndexPath方法中尝试此方法

 static NSString *categoryTableIdentifier = @"CategoryUITableViewCell";

CategoryUITableViewCell *cell = (CategoryUITableViewCell *)[tableView     dequeueReusableCellWithIdentifier: categoryTableIdentifier];
if (cell == nil)
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CategoryUITableViewCell" owner:self options:nil];
    cell = [nib objectAtIndex:0];
}

cell.CustomedLabel.text=[YourArray objectAtIndex:indexPath.row];
return cell;

需要注意的是,在自定义单元格类中,当使用自定义单元格时,必须将插座连接到“表视图单元格”,而不是“文件所有者”

检查xib中的单元格标识符和类名

检查RU是否分配了单元格类CategoriteUitableViewCell的名称我不知道您在哪里搜索,但这不再是推荐的方法。您应该注册nib(在viewDidLoad中是一个好地方),并去掉if cell==nil子句。转到categoriteUItableViewcell.xib-->“显示身份检查器”-->自定义类,然后检查您的类名,这让我抓狂。自从故事板出现后,我就一直在使用它,但我忘了正确使用xibs单元。我的问题是插座连接。我通常倾向于从IB拖动到类,但这会将它连接到文件的所有者,而不是单元格。非常感谢。