Best way to stop loop when viewDisappear

My goal is when the viewDidLoad is fired (refreshed) at a rate of 0.8 sec. And after viewing it disappears (is updated).

In the viewDidLoad call (refres) function:

@proptery disAppear;
- (void)viewDidLoad {
   [super viewDidLoad];
   NSLog(@"TeklifVer-viewDidLoad()");
   self.disAppear = NO;
   [self refresh];    
}

- (void)viewDidDisappear:(BOOL)animated {
   NSLog(@"viewDiddisappear"); 
   self.disAppear = YES;
}

      

on (refresh) function call (refresh): [self performSelector:@selector(refresh) withObject:nil afterDelay:0.8];

if not disAppear.

- (void) refresh
{
    NSLog(@"refresh");

    ...
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSDictionary * responseDictionary = (NSDictionary *)responseObject;

        if (!self.disAppear) {
            ...
            TeklifVerModel * teklifVerModel = [[TeklifVerModel alloc] initWithDictionary:responseDictionary];

            //init labels
            ...

            @try {
                if (teklifVerModel.ihaleStatus == 2) {
                    self.nextPage = true;
                } else if (teklifVerModel.ihaleStatus == 5) {
                    self.ihaleListesi = true;
                }
            }
            @catch (NSException *exception) {
                NSLog(@"error: %@", exception);
            }
        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error: %@", error);
    }];
    [operation start];

    if (self.nextPage) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        IhaleViewController * ihale = [storyboard instantiateViewControllerWithIdentifier:@"ihaleViewController"];
        [self presentViewController:ihale animated:YES completion:nil];
    } else if (self.ihaleListesi) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        IhaleListesiViewController * ihaleListesi = [storyboard instantiateViewControllerWithIdentifier:@"ihaleListesi"];
        [self presentViewController:ihaleListesi animated:YES completion:nil];
    } else if(!self.disAppear) {
        [self performSelector:@selector(refresh) withObject:nil afterDelay:0.8];
    }
}  

      

Magazines

2015-07-03 15:51:24.918 uztb[729:129628] refresh
2015-07-03 15:51:25.189 uztb[729:129628] viewDidDisappear
2015-07-03 15:51:25.720 uztb[729:129628] refresh
2015-07-03 15:51:26.522 uztb[729:129628] refresh
2015-07-03 15:51:27.324 uztb[729:129628] refresh
2015-07-03 15:51:28.127 uztb[729:129628] refresh

      

My problem is when the viewDisapper is still executing (updating). Sometimes the (update) never stops. So when more than one (updated) thread is loaded in this view again, the executed

Question: What is the best approach for stopping (refreshing) a stream when presenting a viewDisappear?

+3


source to share


1 answer


Try using the method cancelPerformSelectorsWithTarget

in viewDidDisappear

. Additional Information.



+3


source







All Articles