ios - Cell not showing updated JSON without html tags with SWIFT 3 -
i have project, using alamofire, swift , xcode. have data coming web url json. json comes in fine in cell, still shows html tags, when print console html tags not there. sure doing wrong @ cell level in code can't seem see is.the code below: help?
code
import uikit import alamofire struct postinput { let mainimage : uiimage! let name : string! let author : string! let summary : string! } class tableviewcontroller: uitableviewcontroller { var postsinput = [postinput]() var mainurl = "https://www.example.com/api" typealias jsonstandard = [string : anyobject] override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. callalamo(url: mainurl) } func callalamo(url : string){ alamofire.request(url).responsejson(completionhandler: { response in self.parsedata(jsondata: response.data!) }) } func parsedata(jsondata : data) { { var readablejson = try jsonserialization.jsonobject(with: jsondata, options: .mutablecontainers) as! jsonstandard // print(readablejson) if let posts = readablejson["posts"] as? [jsonstandard] { post in posts { let title = post["title"] as! string let author = post["author"] as! string guard let dic = post["summary"] as? [string: any], let summary = dic["value"] as? string else { return } let str = summary.replacingoccurrences(of: "<[^>]+>", with: "", options: .regularexpression, range: nil) print(str) print(author) if let imageurl = post["image"] as? string { let mainimageurl = url(string: imageurl ) let mainimagedata = nsdata(contentsof: mainimageurl!) let mainimage = uiimage(data: mainimagedata as! data) postsinput.append(postinput.init(mainimage: mainimage, name: title, author: author, summary: summary)) } } dispatchqueue.main.async { self.tableview.reloaddata() } } } catch { print(error) } } override func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return postsinput.count } override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "cell") // cell?.textlabel?.text = titles[indexpath.row] let mainimageview = cell?.viewwithtag(2) as! uiimageview mainimageview.image = postsinput[indexpath.row].mainimage //(cell?.viewwithtag(2) as! uiimageview).image = postsinput[indexpath.row].mainimage let mainlabel = cell?.viewwithtag(1) as! uilabel mainlabel.text = postsinput[indexpath.row].name mainlabel.font = uifont(name: "helvetica", size:14) let autlabel = cell?.viewwithtag(3) as! uilabel autlabel.text = postsinput[indexpath.row].author autlabel.font = uifont(name: "helvetica", size:12) let sumlabel = cell?.viewwithtag(4) as! uilabel sumlabel.text = postsinput[indexpath.row].summary sumlabel.font = uifont(name: "helvetica", size:12) //(cell?.viewwithtag(3) as! uilabel).text = postsinput[indexpath.row].author return cell! } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } }
here change
let sumlabel = cell?.viewwithtag(4) as! uilabel sumlabel.text = postsinput[indexpath.row].summary
to this
let sumlabel = cell?.viewwithtag(4) as! uilabel let str = postsinput[indexpath.row].summary sumlabel.text = str.replacingoccurrences(of: "<[^>]+>", with: "", options: .regularexpression, range: nil)
Comments
Post a Comment