mrackwitz / MRProgress

Collection of iOS drop-in components to visualize progress
MIT License
2.55k stars 306 forks source link

[AFNetworking] Overlay doesn't disappear or show the final state of the operation #57

Closed 85636682 closed 9 years ago

85636682 commented 9 years ago

i use MRProgressOverlayView+AFNetworking! but in one tableviewcontroller, it always loading,can not stop! how can i do?!

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.contentInset = UIEdgeInsetsMake(-1.0f, 0.0f, 0.0f, 0.0);

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    AFHTTPRequestOperation *operation = [manager GET:[[NSString stringWithFormat:@"http://localhost:3000/api/teams/%@", self.team_id] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.labelTeamName.text = responseObject[@"name"];
        self.teamSportCell.detailTextLabel.text = responseObject[@"sport"];
        self.teamAreaCell.detailTextLabel.text = responseObject[@"area"];
        self.teamMemberCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个", responseObject[@"members_count"]];
        if ([responseObject[@"avatar"] isEqualToString:@"blank.png!80x80"]) {
            self.imageTeamAvatar.image = [UIImage imageNamed: @"avatar.png"];
        } else {
            NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", responseObject[@"avatar"]]]];
            [self.imageTeamAvatar setImageWithURLRequest:imageRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
                self.imageTeamAvatar.image = image;
            } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
                self.imageTeamAvatar.image = [UIImage imageNamed: @"avatar.png"];
            }];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"异常提示" message:@"网络异常" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
    }];

    MRProgressOverlayView *overlayView = [MRProgressOverlayView showOverlayAddedTo:self.view animated:YES];
    [overlayView setModeAndProgressWithStateOfOperation:operation];
    [overlayView setStopBlockForOperation:operation];

    [self.tableView addHeaderWithTarget:self action:@selector(headerRereshing)];
}
mrackwitz commented 9 years ago

What exactly is the problem:

  1. Does the progress overlay fail to show the finish state of the operation and doesn't disappear by itself?
  2. Are you not able to stop the operation, while it is in progress, by pressing the stop button?
85636682 commented 9 years ago

@mrackwitz the problem like one! the progress overlay always loading and can not show the success or fail in first time ! if i popped view and push the controller again, progress overlay worked!

85636682 commented 9 years ago

@mrackwitz qq20140818-2

mrackwitz commented 9 years ago

This seems like the operation is already finished, before it was observed by the progress overlay view. Can you check if this is the case?

85636682 commented 9 years ago

@mrackwitz yes, such is the case! this is my code! https://github.com/85636682/dongqilai-iphone/blob/master/dongqilai/TeamTableViewController.m

mrackwitz commented 9 years ago

I think the best solution will be a new release, which changes the behavior slightly. Probably it would behave more as expected, if the progress view will be hidden, when the operation is finished.

mrackwitz commented 9 years ago

@85636682: You may want to try this branch. Does this fix your issue?