Monday, March 23, 2009

Magnifying Glass in a Text View inside a Table View Cell

Okay, I'm surprised nobody reported this one earlier, but there's a bug in the Chapter 9 application. If you tap-and-hold inside one of the text fields to bring up the magnifying glass, that works, but if you then try to move the cursor position after the magnifying glass comes up, no luck.

My guess as to what's going on is that because UITableView is a subclass of UIScrollView, it intercepts the drag event long enough to mess with UITextField's drag handling code.

After the problem was reported, I did a little research. Turns out there's a workaround for this behavior posted at Stack Overflow by Stephen Darlington .

I'm updating the project source code with the workaround, but it may take a few days to get the new version posted. I've been working through the book projects trying to get them to run under the 3.0 SDK, but need to back out any 3.0-specific changes before I can post the code so that I don't risk unintentionally violating the NDA. In the meantime, here's how you can fix the behavior in the Nav application from the book. In PresidentDetailController.m, add the following method:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}

Then, in viewDidLoad, add the following line of code:

self.editing = YES;

That basic approach should work anywhere you have text fields or text views inside a table. This won't work if you need editing mode on the table, however, if you've got both editable fields and are using edit mode, you're probably violating the HIG anyway and should consider a redesign.

No comments:

Post a Comment