<bdo id='1EjAM'></bdo><ul id='1EjAM'></ul>
<legend id='1EjAM'><style id='1EjAM'><dir id='1EjAM'><q id='1EjAM'></q></dir></style></legend>
<tfoot id='1EjAM'></tfoot>
<i id='1EjAM'><tr id='1EjAM'><dt id='1EjAM'><q id='1EjAM'><span id='1EjAM'><b id='1EjAM'><form id='1EjAM'><ins id='1EjAM'></ins><ul id='1EjAM'></ul><sub id='1EjAM'></sub></form><legend id='1EjAM'></legend><bdo id='1EjAM'><pre id='1EjAM'><center id='1EjAM'></center></pre></bdo></b><th id='1EjAM'></th></span></q></dt></tr></i><div id='1EjAM'><tfoot id='1EjAM'></tfoot><dl id='1EjAM'><fieldset id='1EjAM'></fieldset></dl></div>

  • <small id='1EjAM'></small><noframes id='1EjAM'>

      1. Swift:触发 TableViewCell 以导致另一个 ViewController 中的 UIWebView 中的

        Swift: Triggering TableViewCell to lead to a link in a UIWebView in another ViewController(Swift:触发 TableViewCell 以导致另一个 ViewController 中的 UIWebView 中的链接)

      2. <small id='YHAUD'></small><noframes id='YHAUD'>

          <bdo id='YHAUD'></bdo><ul id='YHAUD'></ul>

              <tbody id='YHAUD'></tbody>
              <tfoot id='YHAUD'></tfoot>
                <legend id='YHAUD'><style id='YHAUD'><dir id='YHAUD'><q id='YHAUD'></q></dir></style></legend>
                1. <i id='YHAUD'><tr id='YHAUD'><dt id='YHAUD'><q id='YHAUD'><span id='YHAUD'><b id='YHAUD'><form id='YHAUD'><ins id='YHAUD'></ins><ul id='YHAUD'></ul><sub id='YHAUD'></sub></form><legend id='YHAUD'></legend><bdo id='YHAUD'><pre id='YHAUD'><center id='YHAUD'></center></pre></bdo></b><th id='YHAUD'></th></span></q></dt></tr></i><div id='YHAUD'><tfoot id='YHAUD'></tfoot><dl id='YHAUD'><fieldset id='YHAUD'></fieldset></dl></div>
                  本文介绍了Swift:触发 TableViewCell 以导致另一个 ViewController 中的 UIWebView 中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我点击 tableViewCell 时,我希望在带有 webView 的新 viewController 中打开一个链接(特定于该单元格的 indexPath.row).

                  When i tap a tableViewCell I want a link (that is specific to that cell's indexPath.row) to open up in a new viewController with a webView.

                  示例:我点击 tableView 中的第三个单元格,www.apple.com 在新的 viewController 上打开.

                  Example: I tap the 3rd cell in the tableView and www.apple.com opens up on a new viewController.

                  我正在尝试使用 didSelectRowAtIndexPath 来做到这一点,但我不知道如何将代码放在一起,以便 linksArray 中的代码(我有所有存储的链接)当我点击 tableViewCell

                  I'm trying to do that with didSelectRowAtIndexPath but I can't figure out how to put the code together so that the code from the linksArray (where i have all the links stored) works together when I tap the tableViewCell

                  我正在从 Parse.com 查询这些链接.这是我的数组:

                  I'm querying these links from Parse.com. This is my array:

                  var linksArray = [NSURL]()

                  我创建了一个名为 LinkViewViewController 的新类,其中我只将 webView 作为 @IBOutlet weak var webView: UIWebView! 连接,仅此而已.我取出了 viewDidLoad 方法,以便可以从具有单元格的 FeedTableViewController 类控制 LinkViewViewController.

                  I created a new Class called LinkViewViewController where I have just the webView connected as a @IBOutlet weak var webView: UIWebView! and nothing else. I took out the viewDidLoad method so that I can control the LinkViewViewController from the FeedTableViewController class that has the cells.

                  下面是我的代码

                   override func tableView(tableView: UITableView,  didSelectRowAtIndexPath indexPath: NSIndexPath) {
                  
                      let myWebView = tableView.dequeueReusableCellWithIdentifier("cell",    forIndexPath: indexPath) as! LinkViewViewController
                  
                      var url = NSURL(string:"(links[indexPath.row])")
                  
                      var request = NSURLRequest(URL: url!)
                  
                      myWebView.webView.loadRequest(links[indexPath.row] as! NSURLRequest)
                  
                  }
                  

                  更新

                  我也在尝试这样做,这可能更合乎逻辑.我正在访问 ProductInfo 类中存储在 Parse 中的链接.productName 数组表示单元格的组织顺序,以便在点击产品名称时可以访问链接.

                  I am also trying to do it this way, which maybe more logical. I am accessing the links that are stored in Parse in the ProductInfo class. The productName array represents in what order the cells are organized in so that the the links can be accessed when tapping on the product name.

                     override func tableView(tableView: UITableView,  didSelectRowAtIndexPath indexPath: NSIndexPath) {
                  
                      let myWebView = tableView.dequeueReusableCellWithIdentifier("cell",    forIndexPath: indexPath) as! LinkViewViewController
                    //Assuming that myWebView is the right method/way to go about it. 
                  
                      var link = PFObject(className: "ProductInfo")
                  
                      link["pLink"] = productName[indexPath.row]
                  
                  
                         /* Code missing: I'm accessing where the link is (the
                          indexPath.row) associated with the productName. 
                          I don't know how to go about this now... How do i access the 
                          webView in the other viewController where the corresponding 
                          link appears?
                  
                          */
                  }
                  

                  我也尝试过创建从单元格到 webView 的 segue,但这也不起作用......

                  I've also tried creating a segue from the cell to the webView but that didn't work either...

                  如何设置 didSelectRowAtIndexPath 以触发链接出现在新视图中?

                  How can I set up the didSelectRowAtIndexPath so that a link is triggered to appear in a new view?

                  思考:info.plist中的NSTransportSecurity也有问题?

                  任何帮助都意味着很多.

                  Any helps means a lot.

                  谢谢.

                  推荐答案

                  你不应该使用 dequeueReusableCellWithIdentifier 来创建你的下一个视图控制器.您应该使用情节提要的 instantiateViewControllerWithIdentifier 来创建实例:在情节提要中为 viewController 设置情节提要 ID"

                  You should not be using dequeueReusableCellWithIdentifier to create your next view controller. You should use the storyboard's instantiateViewControllerWithIdentifier to create the instance: Set the "Storyboard ID" for the viewController in your storyboard

                  例如,如果将其设置为WebViewController",则可以使用以下命令创建实例:

                  If you set it to, for example, "WebViewController" you can then create the instance with:

                  let myWebView = self.storyboard!.instantiateViewControllerWithIdentifier("WebViewController") as! LinkViewViewController
                  

                  我的建议是给 LinkViewViewController 自己的 URL 属性,

                  My recommendation would be to give the LinkViewViewController its own URL property,

                  var url : NSURL?
                  

                  并在创建实例后传递 URL:

                  and to pass the URL after creating the instance:

                  myWebView.url = url
                  

                  然后展示新的 VC:

                  self.presentViewController(myWebView, animated: true, completion: nil)
                  

                  在LinkViewViewController的viewDidLoad中,将URL加载到webView中:

                  In the viewDidLoad of LinkViewViewController, load the URL into the webView:

                  let URLRequest = NSURLRequest(self.url)
                  self.webView.loadRequest(URLRequest)
                  

                  (未经测试输入;请原谅任何拼写错误/可选选项等错误).

                  (Typed without testing; please forgive any typos/errors with optionals etc).

                  最后一点,此方法使用 didSelectRow 方法来创建视图控制器实例并传递 URL.另一种选择是通过 ctrl 从原型单元拖动到视图控制器来使用 segue.然后你需要在 prepareForSegue 方法中实现类似的代码来设置 url.

                  As a final note, this method uses the didSelectRow method to create the view controller instance and pass the URL. Another option would be to use a segue by ctrl-dragging from the prototype cell to the view controller. You then need to implement similar code in prepareForSegue method to set the url.

                  这篇关于Swift:触发 TableViewCell 以导致另一个 ViewController 中的 UIWebView 中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS UIWebView app opens link in Safari(iOS UIWebView 应用在 Safari 中打开链接)
                  Close UIWebView using javascript:window.close();(使用 javascript:window.close() 关闭 UIWebView;)
                  NSCachedURLResponse returns object, but UIWebView does not interprets content(NSCachedURLResponse 返回对象,但 UIWebView 不解释内容)
                  Trouble hiding iAd banner and displaying UIWebView in its place(无法隐藏 iAd 横幅并在其位置显示 UIWebView)
                  Knowing when AJAX has loaded in UIWebView(知道何时在 UIWebView 中加载了 AJAX)
                  Load image/logo in existing HTML input field - UIWebView(在现有的 HTML 输入字段中加载图像/徽标 - UIWebView)

                      <i id='JIKOw'><tr id='JIKOw'><dt id='JIKOw'><q id='JIKOw'><span id='JIKOw'><b id='JIKOw'><form id='JIKOw'><ins id='JIKOw'></ins><ul id='JIKOw'></ul><sub id='JIKOw'></sub></form><legend id='JIKOw'></legend><bdo id='JIKOw'><pre id='JIKOw'><center id='JIKOw'></center></pre></bdo></b><th id='JIKOw'></th></span></q></dt></tr></i><div id='JIKOw'><tfoot id='JIKOw'></tfoot><dl id='JIKOw'><fieldset id='JIKOw'></fieldset></dl></div>

                      <small id='JIKOw'></small><noframes id='JIKOw'>

                        <bdo id='JIKOw'></bdo><ul id='JIKOw'></ul>
                      • <tfoot id='JIKOw'></tfoot>
                          <tbody id='JIKOw'></tbody>
                        <legend id='JIKOw'><style id='JIKOw'><dir id='JIKOw'><q id='JIKOw'></q></dir></style></legend>