mysql - How can I load an image from a Drupal field to UIImageView? -


i'm building app drupal based website. have ios application pulling data mysql database (e.g. article titles , descriptions). know sort of code use display article's corresponding image (uploaded via drupal field) in uiimageview?

here's quick snippet of code i'm using pull text drupal site.

doctorsviewcontroller.h

@interface doctorsviewcontroller : uiviewcontroller {      iboutlet uitableview *doctorstableview;      nsarray *doctors;     nsmutabledata *data;  } 

doctorsviewcontroller.m

- (void)viewdidload {     [super viewdidload];     // additional setup after loading view nib.   [uiapplication sharedapplication].networkactivityindicatorvisible = yes; nsurl *url = [nsurl urlwithstring:@"my url here"];  nsurlrequest *request = [nsurlrequest requestwithurl:url]; [[nsurlconnection alloc] initwithrequest:request delegate:self];  // additional setup after loading view, typically nib. }  - (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response {     data = [[nsmutabledata alloc] init];  }  - (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)thedata {     [data appenddata:thedata];  }  - (void)connectiondidfinishloading:(nsurlconnection *)connection {     [uiapplication sharedapplication].networkactivityindicatorvisible = no;      doctors = [nsjsonserialization jsonobjectwithdata:data options:nil error:nil];     [doctorstableview reloaddata];  }  - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {     uialertview *errorview = [[uialertview alloc] initwithtitle:@"error" message:@"the download not complete - please make sure you're connected 3g or wi-fi." delegate:nil                                               cancelbuttontitle:@"dismiss" otherbuttontitles:nil];     [errorview show];     [uiapplication sharedapplication].networkactivityindicatorvisible = no;   } - (int)numberofsectionsintableview: (uitableview *)tableview  {     return 1;  }  - (int)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return [doctors count];  }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *doctorstableidentifier = @"doctorscell";      doctorscell *cell = (doctorscell *)[tableview dequeuereusablecellwithidentifier:doctorstableidentifier];     if (cell == nil)      {         nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"doctorscell" owner:self options:nil];         cell = [nib objectatindex:0];     }       cell.firstnamelabel.text = [[doctors objectatindex:indexpath.row] objectforkey:@"node_title"];      cell.descriptionlabel.text = [[doctors objectatindex:indexpath.row] objectforkey:@"opening paragraph"];       return cell;  } 

that isn't straightforward sounds - drupal stores field data in specific way, , uris images addressed schema rather having relative or absolute path (e.g. public://path/to/image.jpg opposed /sites/default/files/path/to/image.jpg)

you can image uris node straight db (assuming article type uses standard field_image field):

select fm.uri {file_managed} fm inner join field_data_field_image fi on fi.entity_type = 'node' , fi.bundle = 'article' , fi.deleted = 0 , fi.field_image_fid = fm.fid fi.entity_id = <nid> 

where <nid> node id. there you'll need perform whatever logic need translate paths useful ios app. drupal uses file_create_url() perform same task, that's best starting point inspiration. depending on setup may away doing string replace on public:// http://example.com/sites/default/files/.

long term, might want @ adding services module , consuming rest api in app, instead of querying db directly. it'll take lot of strain of preparing drupal's data out of hands can deal need.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -