[英]Using a url scheme internally with a UIWebView to change a UILabel
I've got a UIWebView which shows up a couple of screens into a UINavigationController: 我有一个UIWebView,它在UINavigationController中显示了几个屏幕:
First View > Second View > View with UIWebView + UILabel
Now, I display a certain page in that web view, which has a link back to my app.... 现在,我在该网页视图中显示某个页面,其中包含一个返回我的应用程序的链接....
myapp://foofoo
I know you can set up a custom URL with (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
and some info.plist poking, but how would change the UILabel, which is one the same screen as UIWebView, by simply clicking the myapp://foofoo link? 我知道你可以用
(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
设置一个自定义URL (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
和一些info.plist戳,但是如何更改UILabel,它是一个与UIWebView相同的屏幕,只需单击myapp:// foofoo链接?
The best way to do this would be through a custom link, and then use the UIWebView delegate method -webView:shouldStartLoadWithRequest:navigationType: to trap requests. 执行此操作的最佳方法是通过自定义链接,然后使用UIWebView委托方法-webView:shouldStartLoadWithRequest:navigationType:来捕获请求。 When you see a request come through with your link in it, you know your action has been triggered.
当您看到包含链接的请求时,您就知道您的操作已被触发。
UIWebView Expose Objective C to JavaScript UIWebView将Objective C暴露给JavaScript
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"scheme = %@",[[request URL] scheme]);
if([[[request URL] scheme]isEqualToString:@"myscheme"])
{
[messageLabel setText:@"HELLO!"];
return NO;
}
else return YES;
}
Make sure your view controller conforms to the UIWebViewDelegate protocol for this to work. 确保您的视图控制器符合UIWebViewDelegate协议,以使其正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.