我将 UITableView
与原型(prototype)单元格一起使用,并希望最顶层的单元格成为“加法器”单元格:当用户点击该单元格时,将执行 segue。由于 UITableView
是动态生成的(顶部的除外)并且单元格正在被重用,我有两个问题:
1 - 是否可以制作一个static
单元格,而所有其他单元格将保留为原型(prototype)单元格?
2 - 如果没有,如何实现这个解决方案?我认为,它必须在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
但我不知道,这个方法是不是适合做这件事的地方。我是否正确,要实现此自定义单元格,我需要检查 indexPath.row = 0
并用自定义替换所需的单元格,同时以编程方式将所有单元格向下移动一行?
最佳答案
Yiu 可以点击您的单元格,您可以创建两个不同的单元格,一个是您的原型(prototype)单元格,一个是您的详细信息
在你的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
AdderCell *cell = (AdderCell*)[tableView dequeueReusableCellWithIdentifier:@"AdderCell" forIndexPath:indexPath];
} else {
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:@"CustomCell" forIndexPath:indexPath];
}
}
在
中点击您的加法器单元格- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
// add data to your row array and reload the tableRow
} else {
// do your tap action
}
}
关于ios - UITableView - 通过点击现有单元格插入新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25058891/