Can I access views when drawn in the drawRect method?
- by GianPac
When creating the content view of a tableViewCell, I used the drawInRect:withFont, drawAtPoint... and others, inside drawRect: since all I needed was to lay some text. Turns out, part of the text drawn need to be clickable URLs. So I decided to create a UIWebView and insert it into my drawRect. Everything seems to be laid out fine, the problem is that interaction with the UIWebView is not happening. I tried enabling the interaction, did not work. I want to know, since with drawRect: I am drawing to the current graphics context, there is anything I can do to have my subviews interact with the user?
here is some of my code I use inside the UITableViewCell class.
-(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];
}
As I said, the view draws fine, but there is no interaction with the webView from the outside. the URL gets embedded into HTML and should be clickable. It is not. I got it working on another view, but on that one I lay the views.
Any ideas?