iOS 7:在textfield上确实更改了我的应用程序崩溃的第一个响应者

时间:2013-09-30 06:39:20

标签: objective-c ios7 textfield

我有可编辑的tableview单元格,当我从表格中的第一个文本字段移动到最后一个文本字段时,它正在崩溃。代码是。下面的代码是用于textfield委托

-(void)textFieldDidBeginEditing:(UITextField *)sender
{
   NSIndexPath *indexpath = [NSIndexPath indexPathForRow:sender.tag inSection:1];
    EditableTextFieldCell *cell = (EditableTextFieldCell *)[self.documentdetailTable cellForRowAtIndexPath:indexpath];
    self.actField = cell.textFieldOne;
    if([self.actField canBecomeFirstResponder]){
        [self.actField becomeFirstResponder];
    }
}
 -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
   if (self.actField == textField) {
      [self.actField resignFirstResponder];
    }
    return YES;
}
-(void)textFieldDidEndEditing:(UITextField*)sender
{
if (self.quantityValue !=nil)
        {
            [self.quantityArray replaceObjectAtIndex:[sender tag] withObject:sender.text];
            [[self.documentItemsArray objectAtIndex:[sender tag]] setQUANTITY:[NSNumber numberWithDouble:[sender.text doubleValue]]];
            [self.documentdetailTable reloadData];
        }
}
- (BOOL)textFieldShouldClear:(UITextField *)textField {
self.quantityValue=@"";
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
-(void)textFieldDidChange:(UITextField *)theTextField
{
    NSLog( @"text changed: %@", theTextField.text);
    self.quantityTextField = theTextField;
    self.actField = theTextField;

}

//add the textfield listeners
[self.quantityTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingDidBegin];

但它崩溃了,我得到的信息如下:

**EditableTextFieldCell _didChangeToFirstResponder:]: message sent to deallocated instance 0xc3c6bf0**

3 个答案:

答案 0 :(得分:8)

我们遇到了同样的问题,因为我们使用“旧代码”来创建/出列自定义UITableViewCells ......

我们要做的是在ViewDidLoad

中添加这些行
[self.myTableView registerClass:[ExpenseListCell class] forCellReuseIdentifier:@"ExpenseListCell"];
[self.myTableView registerNib:[UINib nibWithNibName:@"ExpenseListCell" bundle:nil] forCellReuseIdentifier:@"ExpenseListCell"];

然后“清理”函数cellForRowAtIndexPath只使用dequeue函数:

ExpenseListCell *cell = (ExpenseListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

我怀疑,由于它们包含故事板,dequeueReusableCellWithIdentifier管理单元格的创建,因此您不再需要我们在出列后仍然使用的这些行:

if(cell == nil)
{
    cell = [[[NSBundle mainBundle] loadNibNamed:@"ExpenseListCell" owner:cell options:nil] objectAtIndex:0];
}

NOTA:我们没有使用故事板

更改此项,解决了iOS7上的问题。

答案 1 :(得分:4)

可能这个答案有点愚蠢但是正确答案。 我检查了tableview cellforrowatindexpath并添加了一个标识符

static NSString *EditableTextFieldCellIdentifier = @"EditableCell";

// using custom cells to show textfield and multiple columns
EditableTextFieldCell *cellText = [tableView dequeueReusableCellWithIdentifier:EditableTextFieldCellIdentifier];

这解决了我的问题,也崩溃了。

答案 2 :(得分:0)

有同样的问题。 我通过将标识符放在表视图单元格的nib文件中来修复它。 然后在cellForRowAtIndexPath:

进行出队调用
static NSString *fsCellIdentifier = @"configurationCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:fsCellIdentifier];