在iphone表视图中显示工具提示

时间:2010-07-22 22:44:39

标签: iphone tooltip

我想知道是否有人尝试过。当用户选择行文本中的单词时,我需要在表格视图中显示工具提示。

涉及的复杂性有哪些?这样做的最佳方式是什么?

提前致谢!

1 个答案:

答案 0 :(得分:1)

您可以设计一个显示该工具提示的新视图。 然后,您可以将新视图添加到tableviewcontrollers子视图。这可以在didSelectRowAtIndexPath或类似的东西中完成。您将适当的信息传递给新的新视图并将其添加为子视图。根据您想要传递给视图的数据,为此目的编写自己的viewcontroller可能是值得的。

您需要提供一种关闭工具提示的方法。当然,你必须提供一种方法来选择“以预期的方式”行(如果nessesairy)然后可能是一个双击。我不确定是否已经有了这个框架的方法,但我想你必须编写自己的tableviewcontroller-subclass ......

希望有所帮助

编辑:

嘿曼西,我没有测试过,但是我不知道它应该像这样工作: 您创建自己的UITableView子类。 UITableView继承自UIResponder,因此您可以在tableview-subclass中实现“touchesBegan:” - 方法。在此方法中,您实例化tooltip-view-subclass将其添加为tableview的子视图并将其位置设置为触摸的坐标,您可能希望将水平位置设置为固定或单独计算的值,以防止工具提示显示屏幕外。


#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