当我使用刚刚实现的搜索栏时出现此错误。有些字母可以正常工作,而其他字母会因标题中的错误而崩溃。错误似乎在这里,但我无法弄清楚它有什么问题:
* 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
请帮助我,因为它正在吞噬我的大脑,从昨天开始我就一直坚持下去!