由于未捕获的异常'NSInvalidArgumentException'原因终止应用程序 - >无法识别的选择器发送到实例

时间:2013-07-30 15:44:53

标签: objective-c ios6

当我使用我刚刚实现的搜索栏时,我收到此错误。有些字母有效,而其他字母会因标题中的错误而崩溃。错误似乎在这里,但我无法弄清楚它有什么问题:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BIDPresidentDetailViewController rowImage]: unrecognized selector sent to instance 0x754e360' * 首先抛出调用堆栈:

我的.m文件中有以下代码,它给出了上述错误。我不确定我在代码中犯的错误是什么:

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return kNumberOfEditableRows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];

        label.tag = kLabelTag;
        label.textAlignment = NSTextAlignmentRight;
        label.font = [UIFont boldSystemFontOfSize:14];
        [cell.contentView addSubview:label];

        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(90, 12, 200, 25)];
        textField.tag = kTextFieldTag;
        textField.clearsOnBeginEditing = NO;
        textField.delegate = self;
        textField.returnKeyType = UIReturnKeyDone;
        [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
        [cell.contentView addSubview:textField];
    }

    UILabel *label = (id)[cell viewWithTag:kLabelTag];
    label.text = self.fieldLabels[indexPath.row];

    UITextField *textField = (id)[cell viewWithTag:kTextFieldTag];
    textField.superview.tag = indexPath.row;
    switch (indexPath.row) {
        case kNameRowIndex:
            textField.text = self.president.name;
            break;
        case kFromYearRowIndex:
            textField.text = self.president.fromYear;
            break;
        case kToYearRowIndex:
            textField.text = self.president.toYear;
            break;
        case kPartyIndex:
            textField.text = self.president.party;
            break;            
        default:
            break;
    }

    return cell;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    initialText = textField.text;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (![textField.text isEqualToString:initialText]) {
        hasChanges = YES;
        switch (textField.superview.tag) {
            case kNameRowIndex:
                self.president.name = textField.text;
                break;
            case kFromYearRowIndex:
                self.president.fromYear = textField.text;
                break;
            case kToYearRowIndex:
                self.president.toYear = textField.text;
                break;
            case kPartyIndex:
                self.president.party = textField.text;
                break;
            default:
                break;
        }
    }
}

@end

请帮助我,因为它吃了我的大脑,从昨天起我就被困在它身上了!

1 个答案:

答案 0 :(得分:1)

这里发生的事情是rowImage:被发送到您的视图控制器。 rowImage:应发送给哪些人? (我猜测tableView单元格,但无法确认...)一旦确定应将消息发送到哪个对象,然后更正您的代码。

我无法提供具体信息,因为我没有看到设置或发送rowImage:的位置。