views:

558

answers:

2

I have a UITextView within a UITableView cell. I have been unable to get the keyboard to consistently resign after editing. Detecting DidEndEditing hasn't worked. Adding my own "done" button to the toolbar brings intermittent results. Advice? (Note: This is UITextView not UITextField. Thanks)

A: 

Do you dismiss the table view's controller after you're done editing? I've encountered a non-deterministic crash that occurred when performing [textView resignFirstResponder] plus a call (something like [self doneClicked:nil]) that would dismiss the view controller that hosted the UITableView.

It would release the UITextView and when the call came back into the UITextView method that originated the didEndEditing call, it would crash or behave inconsistently (since the view had been released)..

The solution was to call everything after some delay:

[self performSelector:@selector(doneClicked:) withObject:nil afterDelay:0.5]

Jason
I'm not sure this would work for me.I have the appearance of an overloaded "save" button. When the user is editing the UITextView, that save will dismiss the keyboard and save the UITextView data. At any other time the "save" button will call a different function to save and dismiss.
A: 

adding the textview to the cell:

cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil) {
 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
managedTextView = [[[UITextView alloc] initWithFrame:CGRectMake(7,8,260, 30)] autorelease];
managedTextView.delegate = self;
managedTextView.scrollEnabled = YES;
managedTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
managedTextView.text=thought.managedthought;
[cell.contentView addSubview: managedTextView];
cell.accessoryType = UITableViewCellAccessoryNone;

done button code:

- (void)saveTextView:(id)sender
{
    [managedTextView resignFirstResponder];
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save:)];
    self.navigationItem.rightBarButtonItem = saveButton;
    [saveButton release];
...
}

(the "new" save button is used when saving the entire UITableViewController)