为UIWebView设置一个委托
我如何设置我的UIWebView
委托使用webViewDidFinishLoad
?
在界面文件中指出你感兴趣:
@interface SomethingController : UIViewController <UIWebViewDelegate> {
然后在你的实现中,你将添加这个委托方法:
- (void)webViewDidFinishLoad:(UIWebView *)webView { // Do whatever you want here }
显然SomethingController应该是你的实际控制器,而UIViewController是你正在实现的任何东西。
顺便说一句,这基本上是你如何实现任何代表。
编辑
在基于窗口的应用程序中,假设您的UIWebView在您的应用程序委托中,您只需将其添加到以逗号分隔的委托列表中,如下所示:
@interface YourAppDelegate : NSObject <UIApplicationDelegate, UIWebViewDelegate>
您将在应用程序委托的实现中包含您的webViewDidFinishLoad 。
编辑2
最后,你需要将你的UIWebView连接到你的控制器。 在UIViewController的viewDidLoad
方法中这样做很常见,像这样:
self.yourWebView.delegate = self;
这告诉UIWebView应该在哪里发送消息。
按照下面的屏幕截图
连接你的inYourViewController.h
@interface inYourViewController : UIViewController<UIWebViewDelegate>
现在您已准备好在inYourViewController.m
文件中实现委托方法。
要么
你可以从代码做同样的事情。
通过IBOutlet
连接到视图控制器的webView后,在inYourViewController.m
文件的viewDidLoad
方法写
self.yourWebView.delegate=self
在inYourViewController.h
@interface inYourViewController : UIViewController<UIWebViewDelegate>
现在您已经准备好实现webView.Thanks的委托方法了
- iOS,cocoa,AppiRater – 如何本地化SKStoreProductViewController的取消button
- 根据UICollectionView中的图像dynamic更改单元大小
- UIActivityViewController在iOS 7中
- 删除iOS 5 ARC中的NSNotificationCenter观察者
- 使用播放它的相同button停止声音
- 当我使用git clone从远程获取git时,git_index_entrycount返回0?
- 在UINavigationController中释放ViewControllers的内存
- 不能使用比较魔法logging中的date的谓词
- Phonegap 3.3.0 config.xmlparsing错误