xcode 无法识别的选择器发送到实例自定义单元格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11556736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:56:35  来源:igfitidea点击:

Unrecognized selector sent to instance Custom Cell

objective-ciosxcodeuitableview

提问by Ali Abbas

I am trying to make a Custom Cell for my UITableView.

我正在尝试为我的 UITableView 制作一个自定义单元格。

So, I create a class (UITableViewCell) and I named HomeCell. This class has a xib file with label named titleCell.

因此,我创建了一个类 ( UITableViewCell) 并将其命名为 HomeCell。这个类有一个名为 titleCell 的标签的 xib 文件。

In my cellForRowAtIndexPath method I wrote:

在我的 cellForRowAtIndexPath 方法中,我写道:

HomeCell *cell = (HomeCell *)[tableView dequeueReusableCellWithIdentifier:@"HomeCell"];

    if(cell == nil){
        NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"HomeCell" owner:self options:nil];
        for(id oneObject in xib){
            if([oneObject isKindOfClass:[HomeCell class]]){
                cell = (HomeCell *) oneObject;
            }
        }
    }

    //Get object at index data
    HomeObjectCell *tempObject = [self.dataForCell objectAtIndex:indexPath.row];

    NSLog(@"Title : %@",tempObject.title); // The tempObject.title return a NSString example

    cell.titleCell.text = tempObject.title; // <-- ERROR ! 

When I run the application, I got:

当我运行应用程序时,我得到:

[UITableViewCell titleCell]: unrecognized selector sent to instance 0x6e61890

[UITableViewCell titleCell]:无法识别的选择器发送到实例 0x6e61890

Any idea?

任何的想法?

回答by Neru-J

Are you absolutely sure that:

你绝对确定:

1) .. your class "HomeCell" is named correct for the table cell?Select the cell, select 'identity inspector' -> section 'Custom Class' and take a look

1)..您的班级“HomeCell”为表格单元格命名是否正确?选择单元格,选择“身份检查器”->“自定义类”部分并查看

2) .. referencing outlets with connections to each label/ui image is made?Try select your cell again, select 'Connections inspector' and take a look

2) .. 是否建立了与每个标签/用户界面图像连接的引用插座?再次尝试选择您的单元格,选择“连接检查器”并查看

回答by Apurv

In the description you mentioned that HomeCell has member named titleLable.

在您提到的描述中,HomeCell 具有名为 titleLable 的成员。

In the code you have used cell.titleCell.text.

在代码中您使用了 cell.titleCell.text。

So, I think you should use cell.titleLabel.text instead of cell.titleCell. The crash message is also suggesting same thing that there is no proprty with cell.titleCell exists in HomeCell.

所以,我认为你应该使用 cell.titleLabel.text 而不是 cell.titleCell。崩溃消息也暗示了同样的事情,即 HomeCell 中不存在带有 cell.titleCell 的属性。

回答by John

Check to see if the file owner in the xib file is of Class HomeCell.

检查xib 文件中的文件所有者是否属于HomeCell 类。