Indra Palijama Indra Palijama - 7 days ago 4
iOS Question

implement SDWebImage in modal segue in Objective-C(iOS)

I'm currently working on for my thesis in iOS

I'm making a table view and retrieve the data from my own web service,

after retrieving the data, im passing that data from current row to a new modal view for a detail view (summary view to detail view)

for a note, i can't use the push segue because im already have an navigation controller from SWRevealViewController, the real question is when im getting data from my web service (and its working, i can see my image url in NSLOG) and then use sdwebimage set image with url, the image dont download, there's no incoming network connection from what i see in debug view, here's my code

TableView.m file

- (void) retrieveData{
NSURL * url = [NSURL URLWithString:@getDataURL];
NSData * data = [NSData dataWithContentsOfURL:url];



JSONArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

//set up array objek wisata
ObjekwisataArray = [[NSMutableArray alloc] init];

//loop jsonArray
for (int i = 0; i < JSONArray.count; i++)
{
//add objek wisata
//IdObjek,NamaObjek,DeskripsiObjek,FotoObjek,Latitude,Longitude
NSString * IdObj = [[JSONArray objectAtIndex:i] objectForKey:@"idobjek"];
NSString * NamaObj = [[JSONArray objectAtIndex:i] objectForKey:@"nama"];
NSString * DeskripsiObj = [[JSONArray objectAtIndex:i] objectForKey:@"deskripsi"];
NSString * FotoObj = [[JSONArray objectAtIndex:i] objectForKey:@"foto"];
NSString * LatObj = [[JSONArray objectAtIndex:i] objectForKey:@"latitude"];
NSString * LongObj = [[JSONArray objectAtIndex:i] objectForKey:@"longitude"];


//untuk gambar


//add objek wisata ke array objekwisatarray
[ObjekwisataArray addObject:[[ObjectWisata alloc]initWithNama:NamaObj andDeskripsi:DeskripsiObj andFoto:FotoObj andLatitude:LatObj andLongitude:LongObj andIdObjek:IdObj]];

}

//reload data di table view
[self.tableView reloadData];


}

and this my modal DetailView.m file

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

//load UI
[self setLabels];
[self getWisata:currentWisata];
[self downloadGambar];

NSURL * url = [[NSURL alloc] initWithString:currentWisata.foto];
[GambarWisata sd_setImageWithURL:url];

NSLog (@"URL FOTO : %@" , [NSString stringWithFormat:@"%@",url]);

/*
NSURL * url = [[NSURL alloc] initWithString:[currentWisata valueForKey:@"foto"]];
NSURL * temp = [[NSURL alloc] initWithString:currentWisata.foto];
//[ImageView sd_setImageWithURL:url];
//NSString * temp = url.absoluteString;
//[ImageView sd_setImageWithURL:[NSURL URLWithString:temp]];
[GambarWisata sd_setImageWithURL:temp];

//logfile
NSLog (@"VALUE URL : %@" , [NSString stringWithFormat:@"%@",url]);
NSLog (@"VALUE TEMP : %@" , [NSString stringWithFormat:@"%@",temp]);
*/
backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:self action:@selector(backButton)];
self.navigationItem.leftBarButtonItem = backButton;


}

its actually working when im using only url, in my main view for an opening image, but again, its not working in modal view segue, thanks for your help

Answer

so after i checked again, my url link didn't contain an "http://www." prefix, so i'd managed to do it, here's my code :

    NSString *urlString = currentWisata.foto;
NSURL *webpageUrl;

if ([urlString hasPrefix:@"http://"] || [urlString hasPrefix:@"https://"]) {
    webpageUrl = [NSURL URLWithString:urlString];
} else {
    webpageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.%@", urlString]];
}

Case closed now :)