IOS 7: The first relay my app works with has changed in the textbox

I have an editable tableview cell and when I go from the first textbox to the last textbox in the table it breaks. Code. Below is the code for the textbox 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 crashes and I get a message like:

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

      

+2


source to share


3 answers


Maybe this answer is somewhat silly, but the correct answer. I checked for tableview cellforrowatindexpath and added id

static NSString *EditableTextFieldCellIdentifier = @"EditableCell";

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

      



And that fixed my problem as well as the crash.

+4


source


We had the same problem, and precisely because we used the "old code" to create / delete the UITableViewCells class ...

We needed to add these lines to ViewDidLoad

[self.myTableView registerClass:[ExpenseListCell class] forCellReuseIdentifier:@"ExpenseListCell"];
[self.myTableView registerNib:[UINib nibWithNibName:@"ExpenseListCell" bundle:nil] forCellReuseIdentifier:@"ExpenseListCell"];

      

and then "clear" the cellForRowAtIndexPath function to just use the dequeue function:

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

      



I suspect that since they included storyboards, the dequeueReusableCellWithIdentifier controls the creation of the cells, so you no longer need these lines, which we still use after the dequeue:

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

      

NOTA: We do not use storyboards

By changing this, we have resolved the issue on iOS7.

+8


source


There was the same problem. I fixed it by putting the id in the table cell file nib file. then calling dequeue on cellForRowAtIndexPath:

static NSString *fsCellIdentifier = @"configurationCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:fsCellIdentifier];

      

0


source







All Articles