【发布时间】:2014-03-03 06:48:28
【问题描述】:
我想要的是将所有委托方法集中到一个类中。我可以使用它的默认值或覆盖委托方法。
例如:
ViewController.m
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@end
ViewController.h
#import "ViewController.h"
#import "TableDelegateContainers.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
TableDelegateContainers.h
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return sample.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
return cell;
}
基本上所有 UITableViewDataSource 需要的委托方法都会放到另一个类中。当我将该类导入到 ViewController.h 时,将使用这些方法。如果我愿意,我可以覆盖它们。
这可以通过班级实现吗?还是需要其他实体?
【问题讨论】:
标签: ios iphone objective-c class delegates