iOS 7:在textfield上确实更改了我的应用程序崩溃的第一个响应者 [英] iOS 7: on textfield did change the firstresponder my application is crashing

查看:73
本文介绍了iOS 7:在textfield上确实更改了我的应用程序崩溃的第一个响应者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have editable tableview cell,and when i move from first textfield to last textfield in the table it is crashing.Code is.The below code is for textfield delegate

-(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];

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

But it is crashing and I am getting message like:

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


推荐答案

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

May be this answer somewhat is stupid but the correct answer. I have checked for tableview cellforrowatindexpath and added an identifier

static NSString *EditableTextFieldCellIdentifier = @"EditableCell";

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

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

And this fixed my problem and also crash.

这篇关于iOS 7:在textfield上确实更改了我的应用程序崩溃的第一个响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆