【问题标题】:How to capture displayed html in a variable如何在变量中捕获显示的 html
【发布时间】:2014-10-05 06:42:16
【问题描述】:

应用程序

我有一个包含菜单(表格)的 iOS 应用程序。从菜单中,用户被发送到两个 webView 中显示的相关本地 html 文件。我有兴趣将导航栏的标题设置为 html 文件的名称。

到目前为止

使用

- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{    
   if ([segue.identifier isEqualToString:@"showWeb"]) {

//       NSString *myLabel = rowText ;
       ViewController *detailsTVC = [segue destinationViewController];
       detailsTVC.label = rowText; //rowText;
    }

    if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
        SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;

        swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue,     UIViewController* svc, UIViewController* dvc) {

            UINavigationController* navController =     (UINavigationController*)self.revealViewController.frontViewController;
            [navController setViewControllers: @[dvc] animated: NO ];
            [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
        };

    }

}

当用户在菜单中选择一个项目时,这非常有效。

问题

但是,问题是我在html文件中有链接,链接到其他本地html文件,当用户按下链接时,标题当然不会改变。

基本问题是,我如何捕获/存储包含显示 html 信息的变量?
它不能通过表,因为它不会捕获通过链接的重定向。

【问题讨论】:

    标签: html ios variables uinavigationbar title


    【解决方案1】:

    尝试在您的视图控制器中成为UIWebView 的代表

    - (void)viewDidLoad {
        [super viewDidLoad];
        _webview.delegate = self;
    }
    

    并实现-(void)webViewDidFinishLoad:(UIWebView *)webView委托的方法,然后你可以通过评估javascript document.title得到当前文档标题

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
        NSString *documentTitle = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
        [self setTitle:documentTitle];
    }
    

    【讨论】:

      【解决方案2】:

      我认为这会有所帮助

      -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
       {
           if(indexPath.row == 0)
                self.navigationController.navigationItem.title = @"Your 0th html title";
           if(indexPath.row == 1)
                self.navigationController.navigationItem.title = @"Your 1st html title";
           [self viewDidLoad];
       }
      

      【讨论】:

      • 不幸的是,这并不能解决问题,因为它仅适用于通过我的菜单导航。我需要一种通用方法,在点击 html 文件中的链接时也可以使用。
      • 您能否在 didSelectRowAtIndexPath 上添加您的 segue 代码。我无法追踪实际问题。
      • 它试图让问题更容易理解——解释起来有点困难:)
      猜你喜欢
      • 2015-11-05
      • 1970-01-01
      • 1970-01-01
      • 2013-04-05
      • 2023-01-10
      • 2017-08-10
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      相关资源
      最近更新 更多