GCD on UITableView where NSURL is implemented
i been trying to implement a GCD on my project which shows the fetch data
from an XML, even though its my first time doing it i've
succesfully(maybe) implemented in on nameLabel and detailLabel which are
both string, but the imageLabel(commented part of the code) doesn't give
anything when i try to implement the same GCD as both strings, i dont know
whats happening but when i run the project it gives an unknown exception,
i would like to know if how to implement a GCD on the commented part of
the code so i will be able to show the image in the imageView.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"CustomCell";
dataFileHolder *currentData = [[xmlParser listPopulated]
objectAtIndex:indexPath.row];
CustomCellXMLClass *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [[CustomCellXMLClass
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
NSArray *nib = [[NSBundle mainBundle]
loadNibNamed:@"CustomCellXMLSample" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
myQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(myQueue, ^{
NSString *nameLabel = [currentData nameOfCat];
NSString *dataToCacheLabel = [myCache objectForKey:nameLabel];
if(nameLabel != nil){
dataToCacheLabel = [NSString stringWithString:nameLabel];
if (dataToCacheLabel != nil) {
[myCache setObject:dataToCacheLabel forKey:nameLabel];
dispatch_async(dispatch_get_main_queue(), ^{
[cell.nameLabel setText:dataToCacheLabel];
});
}
}
NSString *detailLabel = [currentData descriptionOfCat];
NSString *stringToCache = [myCache objectForKey:detailLabel];
if (detailLabel != nil) {
stringToCache = [NSString stringWithString:detailLabel];
if (stringToCache != nil) {
[myCache setObject:stringToCache forKey:detailLabel];
dispatch_async(dispatch_get_main_queue(), ^{
[cell.detailLabel setText:stringToCache];
});
}
}
// NSString *imageURL = [currentData imageLink];
// NSData *dataToCache;
// if (imageURL != nil) {
//
// dataToCache = [NSData dataWithContentsOfURL:[NSURL
URLWithString:imageURL]];
// if (dataToCache != nil) {
//
// [myCache setObject:dataToCache forKey:imageURL];
// [cell.imageShow setImage:[UIImage
imageWithData:dataToCache]];
//
// }
// else {
//
// NSURL *imageURL = [NSURL
URLWithString:@"http://i178.photobucket.com/albums/w255/ace003_album/190579604m.jpg"];
// dataToCache = [NSData dataWithContentsOfURL:imageURL];
// [myCache setObject:dataToCache forKey:imageURL];
// [cell.imageShow setImage:[UIImage
imageWithData:dataToCache]];
// }
//
// }
[self.activityIndicator
performSelectorOnMainThread:@selector(stopAnimating)
withObject:nil waitUntilDone:YES];
});
return cell;
}
No comments:
Post a Comment