V
V
Vanya Ivanov2014-03-17 21:18:17
Objective-C
Vanya Ivanov, 2014-03-17 21:18:17

How to implement Activity Indicator in Objective-C?

Help to implement Activity Indicator while the picture is downloading from Url.

if (self.imageView.image == nil) {
        NSString *strUrl = @"http://appro.org.af/wp-content/uploads/2013/03/welcome.jpg";
        NSURL *url = [NSURL URLWithString:strUrl];
        NSData *dataImageUrl = [NSData dataWithContentsOfURL:url];
        UIImage *imageFromUrl = [UIImage imageWithData:dataImageUrl];
        if (imageFromUrl) {
            [self.imageView setImage:imageFromUrl];
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Zarochintsev, 2014-03-17
@Kovalskiy

The library will help you

UIKit+AFNetworking

You can download here .
Implementation:
#import "UIImageView+AFNetworking.h"

    /** Запускаете индикатор активности. */
    [[self activitiIndicator] startAnimating];

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://"]];
    [[self imageView] setImageWithURLRequest:request placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
        [[self imageView] setImage:image];
        /** Останавливаете индикатор активности. */
        [[self activitiIndicator] stopAnimating];
        
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
      /** Если возникла ошибка при загрузке. */
    }];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question