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.



10 comments:

fabiolbj said...

[self.tableView setScrollEnabled:NO] also works.

Don Miller said...

What do you mean "trying to get them to run under 3.0"? I wasn't going to fool with 3.0 until later and are you saying that 2.x code will not ALWAYS work (which means I have to test all my apps in the App Store under 3.0)?

Jeff LaMarche said...

Don:

Didn't mean to scare you.

I can't say much because of the NDA, but overall, most 2.0 code works fine compiled against 3.0. Not 100% at this point, but pretty close, and more than I'd expect from an early beta. But, applications compiled against 2.2 should (in theory) continue to work fine even when installed on a 3.0 phone because they'll still be linking to the 2.2.1 frameworks.

But, in several places, Apple has introduced better ways of doing things then the way we did them in the book under 2.0, and I'm trying to assess our projects in light of those changes to figure out what we want to do with the book in light of 3.0.

Jeff

Don Miller said...

Thanks, and I understand your need to introduce easier and slicker ways under 3.0 code for your samples, but you still have not entirely settled my nerves.

You said "most 2.0 code works fine *compiled* against 3.0". I had no intention of recompiling all my apps immediately (certainly for updates after 3.0 is introduced) against 3.0 (and then create updates for my apps). I guess I just expect them to work with 3.0 without any changes or recompiling even though they were all compiled *against* 2.x.

I guess I want to hear (especially from Apple), that all 25,000 apps compiled against 2.x that used standard and approved calls and APIs will work with 3.0 "as is". Just wishing ;)

And BTW, I think your book is the BEST development book I have ever read (although Wrox books are pretty good) and I read your blogs daily.

Jeff LaMarche said...

Don:

Thanks. Obviously, I can't speak for Apple and I have no inside knowledge, but I think it's certainly Apple's goal to have all the existing applications on the app store continue to work exactly as-is on the new version of the operating system. Backwards compatibility is something Apple's pretty good at. There might be some isolated cases, especially around code that uses private frameworks and methods, but I would put money down that the vast, vast majority of App Store apps will continue to work just fine.

I really wouldn't be too worried. There will be isolated instances, but it won't be widespread or common. That's my guess, at least. The issues I've run into so far are few and minor. So far, there ahve been no code changes needed to make the book code work. I have had to open-then-save a few nib files to get things working properly when compiled against the 3.0 frameworks, but the 2.x versions seem to work mostly fine on 3.0. All-in-all, pretty darn solid for beta-1 release.

And thanks for your kind words about the book and blog.

Jeff

cjr said...

Hi Jeff,

I've been using your generic controller: Multiple Text Field Editing Controller, and this has the same problem but is fixed using your workaround. Though I have noticed that if I run in the simulator then the loupe behaviour is not great but running on an iPhone seems okay...

Aral said...

Interestingly, I'm getting the same issue but in a UITextView that's simply added to a UIView in IB under 3.1.2.

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

Edwin said...
This comment has been removed by the author.
h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels