objective c - Passing a tabelview indexPath.row as String to VC WebView -
i have tableviewcontroller attempting pass through url webview on viewcontroller
i overriding below function, works find if make url static can see in comment out let newslink
constant
let newslink = "http://www.stuff.co.nz/business/industries/69108799/kirkcaldie-stains-department-store-to-become-david-jones"
however below pulling url
indexpath.row
fails reason , passes through nil
value
override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath){ let newslink = (posts.objectatindex(indexpath.row).valueforkey("link") as! string) //let newslink = "http://www.stuff.co.nz/business/industries/69108799/kirkcaldie-stains-department-store-to-become-david-jones" println(newslink) let newswebviewcontroller = uistoryboard(name: "main", bundle: nil).instantiateviewcontrollerwithidentifier("idnewswebviewcontroller") as! newswebviewcontroller newswebviewcontroller.newsurl = nsurl(string: newslink) showdetailviewcontroller(newswebviewcontroller, sender: self) }
if println() below, same output url
ahve hardcoded in test let newslink
constant
println(posts.objectatindex(indexpath.row).valueforkey("link") as! string)
i can't figure out why failing. smarter me can help.
the code on receiving end vc below"
var newsurl : nsurl! //var newsurl = nsurl(string: "http://www.google.co.nz") @iboutlet weak var newswebview: uiwebview! @iboutlet weak var desctextview: uitextview!
and in viewdidappear function
let request : nsurlrequest = nsurlrequest(url: newsurl!)
newswebview.loadrequest(request)
more info
var types
var posts = nsmutablearray() var elements = nsmutabledictionary()
how adding objects
elements.setobject(urllink, forkey: "link") posts.addobject(elements)
could show declaration / structure of "posts" variable?
without more information, thing can think of value of "link" not string, (maybe nsurl) when printed shows content. explain println showing same url cast failing.
when print, or implicitly convert object string (as in println), calls "description" method of object.
for example:
class myurlcontainer { var link:string override func description() -> string { return link } } let url = myurlcontainer() let url.link = "http://www.example.com" println( "my link: \(url)" ) // show link correctly let link = url as? string // nil, url can't casted string
Comments
Post a Comment