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.
Example: I tap the 3rd cell in the tableView
and www.apple.com opens up on a new viewController.
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
I'm querying these links from Parse.com. This is my array:
var linksArray = [NSURL](
)
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.
Here's my code below
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)
}
UPDATE
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?
*/
}
I've also tried creating a segue from the cell to the webView but that didn't work either...
How can I set up the didSelectRowAtIndexPath
so that a link is triggered to appear in a new view?
Thought: NSTransportSecurity
in the info.plist
also an issue?
Any helps means a lot.
Thanks.