Search code examples
xcodeios6uitextfield

UITextField - message sent to deallocated instance "UIKBStringWideAttributeValueForKey:"


After enabling Zombie Objects I am able to see the following error when I try to edit a UITextField (textLvl):

2013-01-13 13:27:10.509 testob[18418:907] *** -[NSConcreteMutableAttributedString
 _UIKBStringWideAttributeValueForKey:]: message sent to deallocated instance 0x2066a1f0

I have posted the portion of code that is causing the issue below, it seems to specifically be the "textField.text = self.storeText;" part - as when I comment this out the problem goes away.

You may be able to tell I am not the most experienced iOS dev, why would my UITextView deallocate after I've set the text? Help please!

Also, I've never heard of "_UIKBStringWideAttributeValueForKey" before - any ideas?

Thanks all!

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    NSLog(@"Text began editing");
 self.storeText = textField.text;
  textField.text = @"";

}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == textLvl){

        if ([textField.text isEqualToString:@""]){
            textField.text = self.storeText;
            NSLog(@"No Text");
        }

        self.conv = [textField.text intValue];
        if (self.conv >= 101){
            textField.text = @"100";
            UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:@"Oh no!" message:@"Can't be higher than 100." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [successAlert show]; }
        }}

Solution

  • This might be a bug internal to the framework. I suggest you add - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField and set the textfield text to nil and then reset the textfield text.