1

I have NSMutableArray , which contains string, datetime, and UIImage. everything is show in my UITableView without image.

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *cellIdentifier =@"Cell";
        CustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

        contact = res[indexPath.row];

        NSString *titleNews = contact[@"title"];
        NSString *newsDateTime = contact[@"datetime"];
        NSString *NewsImageName = contact[@"featured_image"];

        UIImage *image = [UIImage imageNamed:NewsImageName ];

        customCell.customFirstNameLabel.text = titleNews;
        customCell.customLastnameLabel.text = newsDateTime;
        customCell.customImageView.image =image;

        return customCell;
    }

i am trying show data from here .

{
        datetime = "2015-09-10 13:35:33";
        "featured_image" = "http://198.72.115.125/~pratidin/assets/news_images/2015/09/10/thumbnails/bdp-001.jpg";
        "item_id" = 102235;
        "main_news_url" = "http://198.72.115.125/~pratidin/api/detailnews/102235";
        "main_url" = "http://198.72.115.125/~pratidin/api/topnews";
        summery = "\U0997\U09a4 \U0995\U09af\U09bc\U09c7\U0995\U09ae\U09be\U09b8 \U09af\U09be\U09ac\U09a4 \U09ae\U09cb\U09ac\U09be\U0987\U09b2\U09aa\U09cd\U09b0\U09c7\U09ae\U09c0\U09b0\U09be \U0985\U09aa\U09c7\U0995\U09cd\U09b7\U09be\U09af\U09bc…";
        title = "\U098f\U09ac\U09be\U09b0 \U0986\U0987\U09ab\U09cb\U09a8 \U09ec\U098f\U09b8 \U0993 \U09ec\U098f\U09b8 \U09aa\U09cd\U09b2\U09be\U09b8";
    }

this my view . enter image description here would someone help me out how to solve this

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
Ferrakkem Bhuiyan
  • 2,741
  • 2
  • 22
  • 38

5 Answers5

3

Its image url...you can't set image directly by image name...You have to get data from url like this...

NSURL *imgURL = [NSURL URLWithString:NewsImageName];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *imgData = [NSData dataWithContentsOfURL:imgURL];

  dispatch_async(dispatch_get_main_queue(), ^{
        imageView.image = [UIImage imageWithData:imgData];
   });
});

or directly set

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL: NewsImageName]];
Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
  • thanks a lost .. would u kindly help out one this .. How to load images using Lazy load in UITableView – Ferrakkem Bhuiyan Oct 17 '15 at 08:57
  • 1
    glad it helps...and check http://stackoverflow.com/questions/9083454/objective-c-custom-lazy-load-images-uitableview-cell or this ...https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html – Bhavin Bhadani Oct 17 '15 at 09:06
  • i just know one more think . i just want to load an other view using this information .. customCell.customFirstNameLabel.text = titleNews; customCell.customLastnameLabel.text = newsDateTime; customCell.customImageView.image =image; after i clicked - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{} would you kindly let me know ? – Ferrakkem Bhuiyan Oct 19 '15 at 10:46
  • check this....http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – Bhavin Bhadani Oct 19 '15 at 11:02
2

Here your data source contact[@"featured_image"] is an url. So you must load image from url. You can use SDWebImage.framework to load image

            [cell.imageview sd_setImageWithURL:[NSURL URLWithString:contact[@"featured_image"]] placeholderImage:nil options:SDWebImageCacheMemoryOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                if (image) {
                     [cell.imageview setImage:image];
                }
            }];
1

You have to load the image contents from the URL first:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier =@"Cell";
    CustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    contact = res[indexPath.row];

    NSString *titleNews = contact[@"title"];
    NSString *newsDateTime = contact[@"datetime"];
    NSString *NewsImageName = contact[@"featured_image"];

    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:NewsImageName]]];
    //UIImage *image = [UIImage imageNamed:NewsImageName ];

    customCell.customFirstNameLabel.text = titleNews;
    customCell.customLastnameLabel.text = newsDateTime;
    customCell.customImageView.image =image;

    return customCell;
}

Be aware that this will be a synchronous fetching of the images. I suggest you checking the LazyTableImages functions: https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html Or any image caching library like https://github.com/rs/SDWebImage

Dennis Stücken
  • 1,296
  • 9
  • 10
  • i just know one more think . i just want to load an other view using this information .. customCell.customFirstNameLabel.text = titleNews; customCell.customLastnameLabel.text = newsDateTime; customCell.customImageView.image =image; after user clicked - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{} – Ferrakkem Bhuiyan Oct 19 '15 at 10:44
1

Please NSLog your image, and the frame of imageView.

And the [UIImage imageNamed:NewsImageName ]; only load from main bundle, it seems like you are loading image from internet.

Another possible is that you have set the wrong frame so it disappeared.

You are supposed to write in this way

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]];

UIImage *img = [[UIImage alloc] initWithData:data];
Jie Li
  • 1,046
  • 11
  • 17
1

Try this

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL: NewsImageName]];
Mahendra
  • 8,448
  • 3
  • 33
  • 56