title: How to stop functions recursion (in collectionView) by objective c in iOS
body: <p><strong>EDIT:</strong> I admit my design has problem. As long as move my timer to a none-UI-related-function, the problem is solved.</p>
  
  <p>First, I have multiple accounts. I have a collectionView to load one account's information.</p>
  
  <p>Second, I have two functions. One is my collectionView's cellForItemAtIndexPath function. I have a timer in it to call another function to renew the logged account's data.</p>
  
  <pre><code>- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  
      //updateUI methods..
  
      if (// a rare situation ){
           dispatch_async(dispatch_get_main_queue(), ^{
               NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3.0
                             target:self
                             selector:@selector(refreshSingleVMStatusForTimer:)
                             userInfo:nil repeats:NO];
           });
       }
  }
  </code></pre>
  
  <p>and here is refreshSingleVMStatusForTimer function to download all the data from internet then call <code>[collectionView reloadData]</code> to update it.</p>
  
  <pre><code>- (void) refreshSingleVMStatusForTimer :(NSTimer *) timer {
  
      //download the data from internet
      //parse the xml to useful data.
  
      [collectionView reloadData];
  }
  </code></pre>
  
  <p>So these two functions becomes a recursion.</p>
  
  <p>Now If I switch account, my collectionView will load a different account's data in it. But the recursion is still running which will occur error.</p>
  
  <p>I don't know whether I explain my problem clear or not. If you have any question, please tell me.</p>