ios - add UIImage from a URL to a promotion screen in a rubymotion app -


i've had bit of trouble following docs add image promotion screen. pulling post object server contains image url. show post body image if 1 exists in post. recent attempt yields error

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfstring bytes]: unrecognized selector sent instance 0xa813810' 

when running code:

class postscreen < basescreen   attr_accessor :post    def on_load     self.title = "#{self.post['person']['name']}'s post"   end    def will_appear     super     add uilabel.new, {       text: self.post['body'],       font: uifont.systemfontofsize(16),       left: 20,       top: 100,       width: 280,       height: 300,       text_alignment: nstextalignmentcenter,       linebreakmode: uilinebreakmodewordwrap,       numberoflines: 0     }     if self.post['images'].length > 0       add uiimageview.new, {          image: uiimage.alloc.initwithdata(self.post['images'][0]['image_uploader']['medium_square']['url'])       }     end   end end 

i'm quite new rubymotion (obviously) please ask if need more info answer question. i'm assuming pretty straightforward have step away evening thought stackoverflow take crack @ it.

thanks!

-------- update -------------

after digging, believe closer correct:

if self.post['images'].length > 0   url = self.post['images'][0]['image_uploader']['medium_square']['url']   v = uiimageview.new   v.setimagewithurl("url")   add v end 

i using cocoapod sdwebimage believe gives me setimagewithurl method. when run app, v.image null. when run same serious of commands in console, image added uiimageview.

from rubymotion cookbook (https://github.com/iconoclastlabs/rubymotion_cookbook/blob/master/ch_2/17_imageview/app/root_controller.rb) able working

if self.post['images'].length > 0   url = self.post['images'][0]['image_uploader']['medium_square']['url']    image_view = uiimageview.alloc.initwithframe(self.view.bounds)   image_view.contentmode = uiviewcontentmodescaleaspectfit   image_view.center = self.view.center   image_view.setimagewithurl(url)   add image_view end 

i'm sure there lot of ways accomplish goal , maybe better. i'd still love answer question better me , gladly give check mark!


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -