【发布时间】:2016-05-04 10:58:22
【问题描述】:
在过去的几天里,我一直在研究 UIWebViews 和 Delegates,但我完全感到困惑。我想创建一个包含 Web 视图的故事板视图控制器。在 Web 视图中单击按钮时,我想根据对此的答案在视图控制器中触发一些代码:
How to invoke Objective C method from Javascript and send back data to Javascript in iOS?
但是我对如何设置我的委托感到困惑(老实说,我对委托是什么感到困惑,它是与视图控制器相关的 webview 吗?)。我一直在阅读和观看一些教程,但我并不真正理解这个过程,我认为我做得不对。这是我目前所拥有的。
MyViewController.h
#import <UIKit/UIKit.h>
@protocol MyViewControllerDelegate;
@interface MyViewController : UIViewController
@property (nonatomic, weak) id<MyViewControllerDelegate> delegate;
@property (strong, nonatomic) IBOutlet UIWebView *MyWebView;
@end
@protocol MyViewControllerDelegate <NSObject>
-(bool)myWebView:(UIWebView*)myWebView
shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType;
@end
MyViewController.m
#import "MyViewController.h"
@interface MyViewController ()
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
[_MyWebView setDelegate:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewWillAppear:(BOOL)animated
{
}
@end
我不太确定在哪里实现:
-(bool)myWebView:(UIWebView*)myWebView
shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType;
应该去。
如果有人能提供帮助,将不胜感激。
【问题讨论】:
标签: ios objective-c uiwebview delegates