【发布时间】:2011-01-11 18:38:59
【问题描述】:
在创建 tableViewCell 的内容视图时,我在 drawRect: 内部使用了 drawInRect:withFont、drawAtPoint... 等,因为我只需要放置一些文本。事实证明,绘制的部分文本需要是可点击的 URL。所以我决定创建一个 UIWebView 并将其插入到我的 drawRect 中。一切似乎都很好,问题是没有发生与 UIWebView 的交互。我尝试启用交互,但没有奏效。我想知道,由于使用 drawRect: 我正在绘制到当前图形上下文,我可以做些什么来让我的子视图与用户交互?
这是我在 UITableViewCell 类中使用的一些代码。
-(void) drawRect:(CGRect)rect{
NSString *comment = @"something";
[comment drawAtPoint:point forWidth:195 withFont:someFont lineBreakMode:UILineBreakModeMiddleTruncation];
NSString *anotherCommentWithURL = @"this comment has a URL http://twtr.us";
UIWebView *webView = [[UIWebView alloc] initWithFrame:someFrame];
webView.delegate = self;
webView.text = anotherCommentWithURL;
[self addSubView:webView];
[webView release];
}
正如我所说,视图绘制得很好,但是与外部的 webView 没有交互。 URL 嵌入到 HTML 中并且应该是可点击的。它不是。我让它在另一个视图上工作,但我在那个视图上放置了视图。 有什么想法吗?
【问题讨论】:
标签: iphone objective-c uiwebview core-graphics drawrect