1

What I am trying to do is create tooltip functionality so that certain words in my instructional app can be tapped and the definition pops up. For the popup part I plan on using code from “AFInformationView” which provides bubbles on the iPhone.

The part I'm struggling with is how to associate A particular word's location with the bubble. Currently I have the text on a UILabel that is on a custom UITableCell. Since I calculate the row height on the fly with:

[textToUse  sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:CGSizeMake(stop-start, 500)];

I'm not sure what the coordinates for a specific word will be. I was thinking that if I created a custom DataDetectorType that could be the fix.

If anyone knows how to do this or has any other ideas I would be happy to hear them.

Thanks,

Andrew

KingAndrew
  • 1,164
  • 4
  • 21
  • 41

5 Answers5

1

I didn't create a custom UIDataDetectorTypes but Craig Hockenberry did something like it with his TwitterrificTouch.

He uses regular expressions to detect links and other things. I provide it with my keywords and then they become tappable. He places buttons on top of the matching text from the underlying labels. You can google a lot of posts that talk about "putting transparent buttons on top" of various things but Craig's code is the only example/working code I could find.

Here is the link: http://furbo.org/2008/10/07/fancy-uilabels/

KingAndrew
  • 1,164
  • 4
  • 21
  • 41
0

UIWebViews could be a possible approach but on scrolling you should consider that the whole text should be parsed to detect the words.You could use HTMl tags to make them blue and provide the links.But how could i then assign a custom behavior then opening in safari?

Ilker Baltaci
  • 11,644
  • 6
  • 63
  • 79
0

If you want custom data detector you could write an extractor method to primarly patch the links with help of NSregularExpression. For example

NSString regex = @"(http|https|fb)://((\w)|([0-9]*)|([-|_]))+(\.|/)"; to patch alll the links including Facebook URLs inside text like fb://friends.

Then you could use NSattributedString yo mark the links with different colors etc.

ThreeTwenty has a great library called TTTAttributedLabel where you could assign links to certain parts of a text. I also scrolls quite fast if you use it in tableviews

https://github.com/mattt/TTTAttributedLabel

Ilker Baltaci
  • 11,644
  • 6
  • 63
  • 79
0

I don't think this is possible. The (few) Data Detector types that the iPhone currently supports are hard-coded with a integer type id. There does not seem to be a mechanism to extends that list of types.

File a feature request in their bug tracker. I will do the same.

Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88
0

AFAIK, you can't create custom data detectors.

The best approach for this sort of thing seems to be using UIWebViews. At least that's what I did. However, you shouldn't use a UIWebView inside a UITableViewCell. In fact, no subview of a UITableViewCell should respond to user input. So I think the best approach would be to display a UIWebView when the cell is tapped.

Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
  • "So I think the best approach would be to display a UIWebView when the cell is tapped." Could you describe that approach a little more? – KingAndrew Mar 02 '10 at 16:28
  • Assuming your table view is inside a navigation controller, push a UIWebView that displays the table cell's contents using custom, device-generated HTML. – Can Berk Güder Mar 03 '10 at 11:52
  • A good example would be Tweetie 2. When you tap on a tweet in the timeline, a UIWebView that displays the contents of the tweet is pushed. @references and links are interactive in the tweet view, but not in the timeline view. – Can Berk Güder Mar 03 '10 at 11:54
  • 1
    "In fact, no subview of a UITableViewCell should respond to user input." I'm going to disagree with this statement. Apple places buttons on the right and left side of TabelCells depending on the situation. So I think that user interaction with a cell is permissible. – KingAndrew Mar 12 '10 at 15:15
  • @KingAndrew: You're right. Editing mode and detail disclosure buttons are two big exceptions to this rule. Also, this is not in the HIG but, Apple is known for ignoring the HIG occasionally. – Can Berk Güder Mar 12 '10 at 16:11