【发布时间】:2013-09-23 22:34:45
【问题描述】:
我有一个包含 UITableView 的 UIView。 tableview 的委托设置为我的 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:返回什么? -
另外,如果像你说的那样在 UIView 中,你应该把
init中的代码放到awakeFromNib -
你曾经调用过“reloadData”吗?
-
在
willMoveToSuperview中致电reloadData -
您是否有可能没有将 UIView 添加到另一个可见视图中?只有在可见时才会绘制 tableview。否则我看不出你的代码有什么问题。我以前也做过同样的事情,它就像魅力一样。
标签: iphone ios objective-c uitableview