Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.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 使用UITableViewCell时发送到实例的选择器无法识别_Ios_Objective C_Uitableview_Unrecognized Selector - Fatal编程技术网

Ios 使用UITableViewCell时发送到实例的选择器无法识别

Ios 使用UITableViewCell时发送到实例的选择器无法识别,ios,objective-c,uitableview,unrecognized-selector,Ios,Objective C,Uitableview,Unrecognized Selector,我找不到这两张图片和我放在自定义单元格“GameTableCell.H”中的文本框。。。不知道我做错了什么 GameTableCell.H: // #import <UIKit/UIKit.h> @interface GameTableCell : UITableViewCell @property (strong, nonatomic) IBOutlet UILabel *GameTime; @property (strong, nonatomic) IBOutlet UI

我找不到这两张图片和我放在自定义单元格“GameTableCell.H”中的文本框。。。不知道我做错了什么

GameTableCell.H:

  //

#import <UIKit/UIKit.h>

@interface GameTableCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *GameTime;
@property (strong, nonatomic) IBOutlet UIImageView* AwayImage;
@property (strong, nonatomic) IBOutlet UIImageView* HomeImage;


@end
我已经连接的项目是很好的。。。

调用GameTableCell…是主页

主页.H:

#import <UIKit/UIKit.h>

@interface HomePage : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (strong, nonatomic) IBOutlet UITableView *PendingChal;

@property (strong, nonatomic) IBOutlet UITableView *ActiveChal;

@property (nonatomic, strong)NSArray *HomeImages;
@property (nonatomic, strong)NSArray *AwayImages;
@property (nonatomic, strong)NSArray *SportGameInfo;

@end
具体错误如下: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UITableViewCell HomeImage]:未识别的选择器已发送到实例0x79ee11a0” ***第一次抛出调用堆栈:


任何帮助都将不胜感激。。。我觉得我做错了一些事情(我希望如此)

能否尝试在
tableView:cellforrowatinexpath:

if (!cell) {
    NSLog(@"cell was nil");
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

看起来您正在将单元格初始化为UITableViewCell,它不包含HomeImage变量的引用,因此如果dequeueReusableCellWithIdentifier将单元格返回为nil,则必须从XIB加载单元格


希望上述解决方案能解决您的问题。

您能尝试在
表格视图:cellforrowatinexpath:

if (!cell) {
    NSLog(@"cell was nil");
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

看起来您正在将单元格初始化为UITableViewCell,它不包含HomeImage变量的引用,因此如果dequeueReusableCellWithIdentifier将单元格返回为nil,则必须从XIB加载单元格


希望上述解决方案能解决您的问题。

您注册了错误的课程

 [self.PendingChal registerClass: [UITableViewCell class]forCellReuseIdentifier:@"GameTableCell"];
应该像

[self.PendingChal registerClass: [GameTableCell class]forCellReuseIdentifier:@"GameTableCell"];
请在GameTableCell.m文件中使用以下方法

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GameTableCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        self = [topLevelObjects objectAtIndex:0];
    return self;
}
这将解决您的问题。为了清楚的想法,我正在添加一些更多的信息,请通过一次 基本上,我们有两种实现自定义单元格的方法

案例1)注册类:我们有三个步骤

1)在tableview对象中注册我们的自定义单元格类,如下图所示

[self.PendingChal registerClass: [UITableViewCell class]forCellReuseIdentifier:@"GameTableCell"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier=@"GameTableCell";
    GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

//Access all cell properties here.

return cell.
}
2),我们需要使用customcell.m文件中的特定nib手动初始化customcell,如下面所示。

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GameTableCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        self = [topLevelObjects objectAtIndex:0];
    return self;
}
[self.PendingChal registerNib:[UINib nibWithNibName:@"GameTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GameTableCell"];
3)您无需在cellForRowAtIndexPath中检查单元格值nil,您将自动获得所有引用

[self.PendingChal registerClass: [UITableViewCell class]forCellReuseIdentifier:@"GameTableCell"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier=@"GameTableCell";
    GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

//Access all cell properties here.

return cell.
}
案例2:注册nib。

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GameTableCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        self = [topLevelObjects objectAtIndex:0];
    return self;
}
[self.PendingChal registerNib:[UINib nibWithNibName:@"GameTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GameTableCell"];
并直接在您的
cellforrowatinexpath
方法中使用,如下面的

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

        static NSString *CellIdentifier=@"GameTableCell";
        GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

    //Access all cell properties here.

    return cell.
    }
最后不是用

static NSString *CellIdentifier=@"GameTableCell";
            GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
使用以下方法

static NSString *CellIdentifier=@"GameTableCell";
                GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier forIndexPath:indexPath
])

注意:根据此方法覆盖
customcell.m
文件

请通过以下链接进行自定义单元格集成。你会明白这一点的


现在,试着告诉我你注册了错误的课程

 [self.PendingChal registerClass: [UITableViewCell class]forCellReuseIdentifier:@"GameTableCell"];
应该像

[self.PendingChal registerClass: [GameTableCell class]forCellReuseIdentifier:@"GameTableCell"];
请在GameTableCell.m文件中使用以下方法

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GameTableCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        self = [topLevelObjects objectAtIndex:0];
    return self;
}
这将解决您的问题。为了清楚的想法,我正在添加一些更多的信息,请通过一次 基本上,我们有两种实现自定义单元格的方法

案例1)注册类:我们有三个步骤

1)在tableview对象中注册我们的自定义单元格类,如下图所示

[self.PendingChal registerClass: [UITableViewCell class]forCellReuseIdentifier:@"GameTableCell"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier=@"GameTableCell";
    GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

//Access all cell properties here.

return cell.
}
2),我们需要使用customcell.m文件中的特定nib手动初始化customcell,如下面所示。

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GameTableCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        self = [topLevelObjects objectAtIndex:0];
    return self;
}
[self.PendingChal registerNib:[UINib nibWithNibName:@"GameTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GameTableCell"];
3)您无需在cellForRowAtIndexPath中检查单元格值nil,您将自动获得所有引用

[self.PendingChal registerClass: [UITableViewCell class]forCellReuseIdentifier:@"GameTableCell"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier=@"GameTableCell";
    GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

//Access all cell properties here.

return cell.
}
案例2:注册nib。

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"GameTableCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        self = [topLevelObjects objectAtIndex:0];
    return self;
}
[self.PendingChal registerNib:[UINib nibWithNibName:@"GameTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GameTableCell"];
并直接在您的
cellforrowatinexpath
方法中使用,如下面的

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

        static NSString *CellIdentifier=@"GameTableCell";
        GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

    //Access all cell properties here.

    return cell.
    }
最后不是用

static NSString *CellIdentifier=@"GameTableCell";
            GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
使用以下方法

static NSString *CellIdentifier=@"GameTableCell";
                GameTableCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier forIndexPath:indexPath
])

注意:根据此方法覆盖
customcell.m
文件

请通过以下链接进行自定义单元格集成。你会明白这一点的


现在,请尝试让我知道

请添加更多标签,如编程语言和其他与您的应用程序相关的标签query@Anand补充说,谢谢!u使用images.xcsets添加图像???另外添加一个异常断点,是否曾经到达过
“单元格为零”
部分?我建议您不要分配一个
UITableViewCell
,而是分配一个
GameTableCell
是的,我正在从Xcassets中提取它们。最后,我将从一个url中提取我正在尝试让这个“虚拟”表首先在本地运行,然后再进入互联网的深处。请添加更多的标签,如编程语言和其他与您的应用程序相关的标签query@Anand补充说,谢谢!u使用images.xcsets添加图像???另外添加一个异常断点,是否曾经到达过
“单元格为零”
部分?我建议您不要分配一个
UITableViewCell
,而是分配一个
GameTableCell
是的,我正在从Xcassets中提取它们。最终,我将从一个url中提取,我正试图让这个“虚拟”表首先在本地运行,然后再冒险进入互联网的深处。hmmmm没有解决这个问题。相同的问题仍然存在。hmmmm未修复该问题。同样的问题依然存在。我试过这个。。。它让我克服了这个错误。但我的表中没有填充任何内容。此外,我没有收到任何项目为空的错误…您好,您可以尝试[self.PendingChal registerNib:[UINib nibWithNibName:@“GameTableCell”bundle:[NSBundle mainBundle]]forCellReuseIdentifier:@“GameTableCell”];//如果上面编辑的我的解决方案不起作用,请告诉我您的xib类名。我们还有一个解决方案我试过这个。。。它让我克服了这个错误。但我的表中没有填充任何内容。此外,我没有收到任何项目为空的错误…您好,您可以尝试[self.PendingChal registerNib:[UINib nibWithNibName:@“GameTableCell”bundle:[NSBundle mainBundle]]forCellReuseIdentifier:@“GameTableCell”];//如果上面编辑的我的解决方案不起作用,请告诉我您的xib类名。我们还有一个解决方案