How to call a method that would be called if the delegate was not there

I am implementing an optional delegation method in the Cocoa Touch API. I would like to do this, first call the method that was called if I did not implement the delegate ... then make changes to the result ... then return my modified version.

Here is an example:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; {
  /* this line: */ UIView * headerView = [someObject tableView:tableView viewForHeaderInSection:section];
  [headerView setBackgroundColor:[UIColor redColor]];
  return headerView;
}

The marked line does not work. I could set someObject = tableView.delegate, but that just gives me infinite recursion. Is there any trick to make tableView do what it would do if the extra method were not implemented? I do not really hope, but it would be great if possible.

+3
source share
3 answers

, , . ; . UITableView ( ), , , -delegate ( ivar, "" ), , , , , .

UITableView ( UISectionHeaderCell, ), Apple promises , . . , Apple - , .

, , , , .

+6

respondsToSelector - ​​ , , , :)

+3

I assume the UITableView does something like this:

if ([delegate respondsToSelector:@selector(tableView:viewForHeaderInSection:)]) {
    [delegate tableView:self viewForHeaderInSection:section];
} else {
    // Does its own thing instead
}

So, I don’t think you could get the original that way.

+2
source

Source: https://habr.com/ru/post/1716169/


All Articles