tags:

views:

116

answers:

1

I was wondering if anyone has tried it. I need to show a tooltip within a table view when the user selects a word in the row's text.

What are the complexities involved? What is the best way of doing this?

Thanks in advance!

A: 

You could design a new view which that displays that tooltip. You could then add the new view to the tableviewcontrollers subviews. This could be done in the didSelectRowAtIndexPath or something like that. you hand the appropriate information to new new view and add it as subview. depending on the data you want to hand to the view, it might be worth writing an own viewcontroller for that purpose.

you need to provide a way to close the tooltip. And of course you have to provide a way to select the row "in the intended way"(if nessesairy) maybe then a doubletap. Im not sure if there allready is a way to this with the framework, but i guess you'd have to write your own tableviewcontroller-subclass...

Hope that helped

EDIT:

Hey Mansi, i didnt test it, but off the top of my head i'd say it should work sth like this: You create your own UITableView-subclass. UITableView inherits from UIResponder, so you can implement the "touchesBegan:"-method in your tableview-subclass. In this method you instanciate your tooltip-view-subclass add it as subview of the tableview and set its position to the coordinates of the touch, you might want to set the horizontal position to a fixed or seperatly calculated value, to prevent the tooltip from showing off-screen.


#import 
#import 

@interface myTableView : UITableView {
    MyToolTip   *tooltip;
}

@end

#import "myTableView.h"

@implementation myTableView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    tooltip = [[MyToolTip alloc] init];

    CGPoint location = [[touches anyObject] locationInView:self];
    location.x = ([[UIScreen mainScreen] bounds].size.width / 2) - (tooltip.bounds.size.width / 2); 

    tooltip.bounds.origin = location;
    [self addSubview:tooltip];
    [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(removeTooltip) userInfo:nil repeats:NO];
}

- (void)removeTooltip {
    [tooltip removeFromSuperview];
}


@end
Tobi
Thanks Tobi. But, what I'm trying to understand is how do you compute where in the table view to display the tooltip. It needs to be displayed on top of a specific word in the sentence. Is there a way of computing coordinates for a specific word within the sentence?I hope I was able to explain my problem...
Mansi
im not sure if you can get the coordinates of a cell from the framework. but as mensioned above, since the user taps the row for which the tooltip should be shown, i think the touch-coordinates will do the trick. if you want to be independent from the touch-coords im afraid you'd have to "measure" the cell's height and calculate their vertical position with the row-number.
Tobi
oh maybe i got you wrong again, are you talking about specific positions inside a single cell?
Tobi
Yes, I am talking about specific positions inside a single cell. So if the cell contains a text for example "Hello, how are you John?" and the words "Hello" and "John" are special words. If the user clicks on any of these words, a tooltip should appear, pointing to that word and showing some details related to that word...
Mansi
So now, I will be using the UIStringDrawing to render the text. If that works, I will put some code out here.Thanks for the help!
Mansi
Used the three20 library for this. I had to use it for some other feature in my project and found that they already have this facility. It's easy to use and is well tested too.
Mansi