正如评论中所说,奇怪的结构,但如果你坚持,那没关系。我建议只使用简单的UITableView。
假设您有IBOutlet 到UITableView 和UIScrollView...
在viewWillAppear中添加代码之前,添加:
float cellHeight = 65.0f;
int numberOfCells = 3;
在- (void)viewWillAppear:animated中,在[super viewWillAppear:animated]之后添加以下内容:
// remember fill the table with data using UITableViewDataSource's functions first
// refresh UITableView data
[tableView reloadData];
// resize UITableView
[tableView setFrame:CGRectMake(0, 0, tableView.frame.size.width, cellHeight * numberOfCells)];
// make UIScrollView the same size as UITableView
[scrollView setContentSize:tableView.frame.size];
[scrollView setNeedsDisplay];
// remember to lock tableView's scrolling, either in code / Interface Builder
[tableView setScrollEnabled:NO];
在UITableViewDelegate的委托方法中:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return numberOfCells;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return cellHeight;
}
最后,如果您想再次验证是否有任何表格单元格不在视线范围内,您可以使用:
- (NSArray *)visibleCells