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.
objective-c - argument of parent function passed into child block is not changed inside
-
23-07-2023 - |
문제
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];
}];
}];
}
해결책
제휴하지 않습니다 StackOverflow