문제

I'm new to ios and objective-c programming and currently I'm a bit confused with this behavior -

I have function which calls handler with block inside. This function receives different arguments but inside block handler it's not changed, it stays as it was declared on first call:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 
{
   // called with different strings - "foo", "bar"
   [self startSearchText:searchBar.text];
}

- (void)startSearchText:(NSString *)text 
{
  __block CGFloat page = 1;
  __weak LSAllFavoritesViewController *weakSelf = self;

   // initial search request
  [weakSelf makeSearchWithText:text byPage:page success:^{
    page += 1;
   }];

  // infinite scrolling
  [weakSelf.searchDisplayController.searchResultsTableView addInfiniteScrollingWithActionHandler:^
   {
    // text will remain "foo" for all next requests
    [weakSelf makeSearchWithText:text byPage:page success:^{
         page += 1;
         [weakSelf.searchDisplayController.searchResultsTableView.infiniteScrollingView stopAnimating];
    }];
  }];
}
도움이 되었습니까?

해결책

From the source code, it is obvious that addInfiniteScrollingWithActionHandler: does nothing except the first time it got called. You should store text into a private variable instead, so you can always get latest value from inside the block.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top