我有一个包含UITableView的UIView。UITableView的代理设置为我的UIView,但它从未调用代理方法:
-(id)init {
self = [super init];
if (self) {
self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.scrollEnabled = NO;
self.tableView.layer.cornerRadius = PanelCornerRadius;
[self addSubview:self.tableView];
}
return self;
}
#pragma mark - UITableViewDelegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"height for row");
int height = [self heightForRowAtIndexPath:indexPath];
return height;
}
#pragma mark - UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"number of rows");
if (self.manager.fetchOperation.dataFetchProblem) {
return 1;
}
int numberOfRows = [self.delegate numberOfSectionsInPanel:self];
return numberOfRows;
}
我已经探索了我能想到的每个选项,但似乎找不到问题的根源。
编辑:包括了numberOfRowsInSection。 它有可能返回0,只是从来没有机会,因为"行数"NSLog从未被调用过。
numberOfRowsInSection:
返回什么? - Lanceinit
中的代码放到awakeFromNib
中。 - LancewillMoveToSuperview
中调用reloadData
。 - Lance