Take the 2-minute tour ×
@property (nonatomic, retain) NSString *text;

with this property I am saving text from a textfield I create in a UITableViewCell

static NSString *cellIdentifier = @"fieldTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil) {

    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 12, 275, 25)];
    textField.clearsOnBeginEditing = NO;
    textField.returnKeyType = UIReturnKeyDone;
    [textField addTarget:self action:@selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
    [cell.contentView addSubview:textField];

// re-get textField and set tag to section
if (section == 1) {
    textField.text = self.text; // Where the problem is
    textField.tag = section;


- (void)textFieldDone:(id)sender {
    UITextField *field = sender;

    if (field != nil) {
         NSInteger section = field.tag;

        if (section == 1) {
            self.text = field.text;

However, back in cellForRowAtIndexPath is setting textField.text back to the saved text. The problem is when it does this it is giving me

-[CFString _isNaturallyRTL]: message sent to deallocated instance 0x2c459ff0

when I look at self.text in cellForRowAtIndexPath in the debugger, it says it is NSZombie_NSString ... so somehow it is getting dealloc'd. I have tried setting the property to copy, copying the string using [initWithString]... Why is the string getting dealloc'd?

share|improve this question
Why are you copying self.text back to textField.text ? And did you mean indexPath.row ==1 instead of section ==1 ? –  Legolas Jun 15 '11 at 14:58
Yes, I mean section. I have 2 sections, section zero with 7 fields backed by seperate data, and section one with 1 field that I am backing with the NSString. When the view gets recycled, I need to be able to reassign the textField.text with my backing data. –  Tom Fobear Jun 15 '11 at 15:09
If what you want is each cell has a text field, the better practice is to subclass your table view cell, and let the cell to manage the life cycle of the text field. –  zonble Jun 15 '11 at 16:07
add comment

3 Answers

Where are you setting a value to the "text" property?

Try setting it as self.text = [NSString stringWithFormat:@"This is some text"];

That being said, as a best practice I highly suggest not using names like "text" that could be confused with native object properties (UILabel.text, UITextField.text, etc.). It helps in the long run :)

share|improve this answer
for the sake of confidentiality I usually change my identifier names on SO. But that is good advice! –  Tom Fobear Jun 15 '11 at 20:18
Funny you mention that but I was going to get on that today :) –  Sid Jun 15 '11 at 21:01
add comment
up vote 0 down vote accepted

once bitten twice shy. Except, Ive already made this mistake.

in my acctual code I had

text = textField.text; //var declared in class

But I meant

self.text = textField.text; //to use the property like in my example
share|improve this answer
add comment


textField.delegate = self;
tableView.dataSource = self;
share|improve this answer
+1 because this question was unfair, my example would have worked. –  Tom Fobear Jun 15 '11 at 15:27
.............. lol. –  Legolas Jun 15 '11 at 15:40
add comment

Your Answer


