Hello, I created a instance of my ViewController(TimeLineViewController), which will be presented. This ViewController contains a UITableView, which gets the cells from a instance of my TableViewCell. So the ViewController creates an instance of the TableCellView. The TableViewCell contains a UITextView with enabled weblinks. Now I want to disable the function that safari opens. I did a subclass of the UITextView and:
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener
{ NSLog(@"request: %@", request); //Console shows the link
}
Now I want that with a click on the weblink a new ViewController(WebViewController) appears. The problem is that the TableViewCell can´t "open" a new ViewController. So I tried this: In the TableViewCell:
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener
{ NSLog(@"request: %@", request);
TimeLineViewController * web = [[TimeLineViewController alloc]init];
[web loadView];
}
And in the ViewController:
- (void)loadWeb{
WebViewController *lust = [[WebViewController alloc] initWithNibName:nil bundle:nil];
lust.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:lust animated:YES];
[lust release];
}
The problem is that he always just reload the TimeLineViewController, but doesn't load the WebViewController. Why? How can I fix it? (I know that the WebViewController doesn't get the weblink in my posted code and I know how to do it. That shouldn't be the problem, when I know, how to fix my problem.)
Thanks for your help! If you have questions, just ask - Sorry for my bad English.
UPDATE: I did what Frank mention, but I doesn't work. I created a WebViewTableCellDelegate.h with:
@protocol WebViewTableCellDelegate
-(void)loadWeb;
@end
Then I created a instance variable of the WebViewDelegate in the TableViewCell:
__weak NSObject <WebViewTableCellDelegate> *_delegate;
and in the .m:
@interface UITextView (Override)
@end
@class WebView, WebFrame;
@protocol WebPolicyDecisionListener;
@implementation UITextView (Override)
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener
{ NSLog(@"request: %@", request);
[_delegate loadWeb];
}
@end
In my TimeLineViewController I implemented the WebViewTableCellDelegate with <> and in the line, where I create the cells, I set the owner to self:
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
cell = tableCell;
}
Why doens´t it work? There is no error-warning.