0

I was looking into an open source pull-to-refresh control and it swizzle lifecycle methods on a UIViewController category like so:

- (void)INBPullToRefreshView_viewWillAppear:(BOOL)animated
{
    [self setClearNavigationBar:YES];
    [self INBPullToRefreshView_viewWillAppear:animated];
    UITableView *tableView = self.pullToRefresh.tableView;
    tableView.contentOffset = tableView.contentOffset;
    self.pullToRefresh.showPullToRefresh = YES;
}

I get that when viewWillAppear was called it mapped to the above method, and that calling [self INBPullToRefreshView_viewWillAppear:animated]; will map to the original viewWillAppear.

However, what does the following do?:

tableView.contentOffset = tableView.contentOffset;

Here's the github source for the control.

OdieO
  • 6,836
  • 7
  • 56
  • 88

2 Answers2

3

I would suspect the author is trying to use a side-effect of setContentOffset:, perhaps forcing a recalculation. But the author seems active on the project, so why not ask intmain in a github issue?

Of course the standard warnings that this kind of method swizzling is extremely dangerous and fragile apply.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
2

I believe you're asking something unrelated to the swizzling itself?

Setting the contentOffset property will cause a scrollViewDidScroll: message sent to the delegate of your object. There's probably a cleaner way to accomplish that (or at least it should have a comment)

KirkSpaziani
  • 1,962
  • 12
  • 14