开发者

Can't get keyboard to resign consistently with UITextView in UITableViewCell

I have a UITextView within a UITa开发者_StackOverflow中文版bleView 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)


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]


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜