I was wondering if anyone has tried it. I need to show a tooltip within a table view wh开发者_如何转开发en 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!
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
精彩评论