[英]UITableView - insert new row by tapping on existing cell
我将UITableView
与原型单元一起使用,并且希望最上面的单元是“加法”单元:当用户点击该单元时,将执行segue。 由于UITableView
是动态生成的(最上面的一个除外)并且单元正在重用,所以我有两个问题:
1-是否可以制造一个static
单元格,而其他所有单元格仍为原型单元格?
2-如果没有,如何实施此解决方案? 我认为,必须在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
但我不知道,这种方法正确吗? 我是否正确,要实现此自定义单元,我需要检查indexPath.row = 0
并用自定义替换所需的单元,同时以编程方式将所有单元向下移动一排吗?
Yiu可以在“ Tap of Your”单元中进行操作,您可以创建两个不同的单元,一个为原型单元,另一个为您的详细信息
在你的
- (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];
}
}
在您的Adder单元中点击
- (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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.