ios - UITableView - 通过点击现有单元格插入新行

标签 ios objective-c uitableview

我将 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/

相关文章:

iphone - 在 ios 上启动应用程序时进行登录 View 的最佳实践

ios - 当根 Controller 是 UIHostingController 时隐藏 UINavigationController 的 navigationBar

iphone - 在应用程序更新时,自定义 plist 文件将得到更新,或者我们需要做些什么吗?

ios - 滚动 UIScrollView - 阻塞主线程

ios - UIPickerView 依赖于 UITableView

ios - Storyboard和 CustomCells

ios - 应用程序未运行或终止时的通知

objective-c - Watchkit:显示大量数据的最佳方式

objective-c - 用作全局变量的 AppDelegate 变量不起作用

iphone - BackgroundView 不适应 Grouped UITableView 中的圆角