How to upload thumbnail image for ios rss feed table cell from xml feed -


almost finished rss app need create work. still new xcode , have tried many different open source code's available out there. found 1 more suited needs last thing need thumbnail images work table view cells. articles title , description in cells load fine, when tried re-write code image comes blank.

the project made work google news rss : https://news.google.com/?output=rss. rss using : http://www3.westchestergov.com/home/all-press-releases?format=feed&type=rss

now, part of code believe deals image downloading table view cells :

    override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! uitableviewcell     let newsitem = rssdatalist[indexpath.row]     cell.imageview?.image != nil     cell.textlabel?.text = newsitem.title     cell.detailtextlabel?.text = newsitem.summary      // use cached image or download new image cell     if let imgurlstring = newsitem.imgurl, let cachedimage = imagescache[imgurlstring] {         cell.imageview?.image = cachedimage      } else if let imgurlstring = newsitem.imgurl {          // need set blank image imageview show downloaded image         let blank = uiimage(named: "blank.jpg")         var tempimage = cgimagecreatewithimageinrect(blank?.cgimage!, cgrect(x: 0, y: 0, width: 80, height: 80))         cell.imageview?.image = uiimage(cgimage: tempimage)          dispatch_async(dispatch_get_global_queue(qos_class_user_interactive, 0)) {             var downloadedimg = uiimage()              if let imgurl = nsurl(string: imgurlstring), let imgdata = nsdata(contentsofurl: imgurl), let img = uiimage(data: imgdata) {                 downloadedimg = img             } else {                 println("error while downloading img")             }              dispatch_async(dispatch_get_main_queue()) {                 if let celltoupdate = tableview.cellforrowatindexpath(indexpath) {                     celltoupdate.imageview?.image = downloadedimg                 }             }         }     }      return cell }  

for google rss works fine, , when searched through code thier rss see thier images stored :

img src="//t3.gstatic.com/images?q=tbn:and9gcshnlu8ojizbnm5ggunjte5zwbwywen_xvjwglmygudzodjsac5s62-gagtxttu4si8bvrc6w1k" alt=""  

for rss using images stored :

<img style="border: 1px solid #cccccc; margin-bottom: 2px; margin-left: 10px; float: right;" src="http://www3.westchestergov.com/images/stories/newsprimary2015/ferc-logo.jpg" alt="ferc-logo" width="333" height="222"  

can shed light on how able change code around can work rss feed using? last piece of puzzle me , if can work can put app behind me.

also, if helps, there piece of code in newsitem.swift class deals images too:

    private func updatedescriptionhtmlimgurl() {     descriptionhtml = descriptionhtml.stringbyreplacingoccurrencesofstring("<img style=", withstring: "src=http://") }  

thanks in advance

the following snippet extract url string using regex.

var str = // rss image string let regex = nsregularexpression(pattern: "(http://)(.*?)(?=\")", options: nsregularexpressionoptions.allzeros, error: nil)  var urlstring = "" if let result = regex?.firstmatchinstring(str, options: .allzeros, range: nsmakerange(0, count(str))) {     urlstring = (str nsstring).substringwithrange(result.range) }  println(urlstring) // print: http://www3.westchestergov.com/images/stories/newsprimary2015/ferc-logo.jpg 

edit: how implement

i recommend creating function conversion. this:

func convertrssimagetourl(rssimage: string) -> nsurl? {     let regex = nsregularexpression(pattern: "(http://)(.*?)(?=\")", options: nsregularexpressionoptions.allzeros, error: nil)      if let result = regex?.firstmatchinstring(rssimage, options: .allzeros, range: nsmakerange(0, count(rssimage))) {         return nsurl(string: (rssimage nsstring).substringwithrange(result.range))     } else {         return nil     } } 

then add code, so:

change line

} else if let imgurlstring = newsitem.imgurl { 

to

} else if let imgurl = convertrssimagetourl(newsitem.imgurl) { 

and delete row:

let imgurl = nsurl(string: imgurlstring),  

since have unwrapped nsurl.

side note: not tested, should give enough implement on own


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -