escoz / QuickDialog

QuickDialog - Quick and easy dialog screens for iOS
http://escoz.com/open-source/quickdialog
Other
3.07k stars 637 forks source link

Custom QuickDialogTableDelegate #602

Open vjpr opened 10 years ago

vjpr commented 10 years ago

If I want to override some methods in the QuickDialogTableDelegate what is the best way to do this?

For example I might like to create a custom header so I'll want to implement my own - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)index method.

What I am thinking about at the moment is:

# QuickDialogTableView.m
...
quickDialogDelegate = [[QuickDialogTableDelegate alloc] initForTableView:self];
self.delegate = quickDialogDelegate;

Is the best way to set a custom delegate extending QuickDialogTableDelegate?

vjpr commented 10 years ago

One inconvenince to the above approach is that _tableView is private.

@private
    __unsafe_unretained QuickDialogTableView *_tableView;

Is there a reason for this being private instead of @protected?

vjpr commented 10 years ago

After more investigation it looks like I should be extending QAppearance, and for my first example overriding: [appearance buildHeaderForSection:section andTableView:(QuickDialogTableView*)tableView andIndex:index];.

It would still be nice to extend the delegate nicely.

vjpr commented 10 years ago

Workaround for extending @private _tableView:

Define in your custom delegate:

# .h
@interface CustomDelegate : QuickDialogTableDelegate {
  @private
    __unsafe_unretained QuickDialogTableView *_myTableView;
}
@end

# .m
- (id <UITableViewDelegate, UIScrollViewDelegate>)initForTableView:(QuickDialogTableView *)tableView {
  self = [super initForTableView:tableView];
  if (self) {
    _myTableView = tableView;
  }
  return self;
}