我有一个包含120个数字的表格视图。我想知道是否可以在每12个数字之后在我的tableview中添加一个部分。这比拥有10个12个数字的独立数组并将每个数组添加到不同的部分要容易得多。 谢谢!
答案 0 :(得分:1)
我正在读你的问题,想知道我是否在这里遗漏了一些东西,但是:是的,这是可能的。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 10;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 12;
}
...然后在tableView:cellForRowAtIndexPath:
方法中,使用indexPath.section * 12 + indexPath.row
作为120号数组的索引。