【问题标题】:Unrecognized selector error on custom table view cell自定义表格视图单元格上无法识别的选择器错误
【发布时间】:2012-10-22 20:23:54
【问题描述】:

我正在使用自定义单元格来显示信息。当我使用 NSString 将信息传递给 UILabel 时,出现以下错误。

错误:

[HITEstimationCustomViewCell isEqualToString:]:无法识别的选择器发送到实例 0x6892f80

2012-10-23 01:38:04.821 MyApp[13298:c07] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[HITEstimationCustomViewCell isEqualToString:]:发送了无法识别的选择器到实例 0x6892f80

单元格详细信息:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"EstimationCellIdentifier";

    static BOOL nibsRegistered = NO;

    if(!nibsRegistered)
    {
        UINib *nib = [UINib nibWithNibName:@"HITEstimationCustomViewCell" bundle:nil];

        [tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];

        nibsRegistered = YES;
    }


    HITEstimationCustomViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    NSUInteger row = [indexPath row];
    NSString *rowData =[estimationListArray objectAtIndex:row];

    cell.nameTextField = rowData;
    cell.emailIdTextField = [estimationListArray objectAtIndex:row];

return cell;
'

实例:

HITEstimationCustomViewCell *newCell = [[HITEstimationCustomViewCell alloc] initWithNameField:@"Michael" emailId:@"mike@mike.com" skypeId:@"mrmike" hourlyRate:@"$25" numberOfHours:@"20" totalCost:@"$1000"];

    NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:newCell, nil];

self.estimationListArray = myArray;

界面:

@interface HITEstimationCustomViewCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *nameField;
@property (weak, nonatomic) IBOutlet UILabel *totalCost;
@property (weak, nonatomic) IBOutlet UILabel *hourlyRate;
@property (weak, nonatomic) IBOutlet UILabel *emailId;
@property (weak, nonatomic) IBOutlet UILabel *skypeId;
@property (weak, nonatomic) IBOutlet UILabel *numberOfHours;

@property (copy, nonatomic) NSString *nameTextField;
@property (copy, nonatomic) NSString *totalCostTextField;
@property (copy, nonatomic) NSString *hourRateTextField;
@property (copy, nonatomic) NSString *emailIdTextField;
@property (copy, nonatomic) NSString *skypeIdTextField;
@property (copy, nonatomic) NSString *numberOfHoursTextField;


-(id)initWithNameField:(NSString *)name emailId:(NSString *)email skypeId:(NSString *)skype hourlyRate:(NSString *)hourlyPrice numberOfHours:(NSString *)Hours totalCost:(NSString *)total;


@end

实施:

@implementation HITEstimationCustomViewCell

@synthesize nameField;
@synthesize totalCost;
@synthesize hourlyRate;
@synthesize emailId;
@synthesize skypeId;
@synthesize numberOfHours;

@synthesize nameTextField;
@synthesize totalCostTextField;
@synthesize hourRateTextField;
@synthesize emailIdTextField;
@synthesize skypeIdTextField;
@synthesize numberOfHoursTextField;



-(void)setNameTextField:(NSString *)n
{
    if(![n isEqualToString:nameTextField])
    {
        nameTextField = [n copy];

        nameField.text = nameTextField;
    }
}


-(id)initWithNameField:(NSString *)name emailId:(NSString *)email skypeId:(NSString *)skype hourlyRate:(NSString *)hourlyPrice numberOfHours:(NSString *)Hours totalCost:(NSString *)total
{

    self = [super init];
    if(self)
    {

        self.nameTextField = name;
        self.emailIdTextField = email;
        self.skypeIdTextField =skype;
        self.hourRateTextField = hourlyPrice;
        self.numberOfHoursTextField = Hours;
        self.totalCostTextField = total;

    }

    return self;
}

我是 IOS 和 XCode 的新手,我尝试了很多在论坛上找到的东西,但无法解决问题。

【问题讨论】:

  • 请不要对我们大喊大叫。我们 stackoverflowians 很容易被吓到。

标签: objective-c ios


【解决方案1】:

错误信息告诉你你需要知道的一切:

[HITEstimationCustomViewCell isEqualToString:]: unrecognized selector sent to instance
       ^                              ^
       Class Name                     Method Name

您在 HITEstimationCustomViewCell 的实例上调用 isEqualToString:

查看您调用isEqualToString: 的位置并向后工作。您将看到您将 HITEstimationCustomViewCell 实例分配给 nameTextField 属性,而不是 NSString

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2012-05-26
    • 1970-01-01
    相关资源
    最近更新 更多