私はUITableView
を持っています。今日、私はそれが別のファイルにUITableViewDataSource
とUITableViewDelegate
だ移動しました。それはこのように見えます。外部データソースとデリゲートのためにUITableViewが正しく読み込まれませんか?
@interface TableDelegate : NSObject <UITableViewDelegate>
@property (nonatomic, assign) id delegate;
@end
@interface TableDataSource : NSObject <UITableViewDataSource>
@property (nonatomic, assign) id delegate;
@end
@implementation TableDelegate
@synthesize delegate;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
NSLog(@"heightForHeaderInSection");
return 20.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSLog(@"header!");
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 20)];
headerView.backgroundColor = [UIColor whiteColor];
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"heightForRowAtIndexPath");
return 48.0f;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[((UIViewController *)delegate).view endEditing:YES];
}
@end
@implementation RequestTableDataSource
@synthesize delegate;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 6;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"numberOfRowsInSection");
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
NSLog(@"cellForRowAtIndexPath");
cell.textLabel.text = @"Test";
return cell;
}
@end
私はその後、私の構築UITableView
次のように:私は私のアプリをコンパイルするとき
TableDelegate *tableDelegate = [[TableDelegate alloc] init];
tableDelegate.delegate = self;
TableDataSource *tableDataSource = [[TableDataSource alloc] init];
tableDataSource.delegate = self;
self.testTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.testTable.delegate = tableDelegate;
self.testTable.dataSource = tableDataSource;
[self.view addSubview:self.testTable];
は今、私は任意のコンテンツずに空白UITableView
を取得します。私はcellForRowAtIndexPath
とviewForHeaderInSection
のコンソールでログの一部ではなく、ログを参照してください。私はここで間違って何をしていますか?
'TableDataSource'と' TableDelegate'への強い参照を保持している任意のオブジェクトはありますか? – crizzis