ios - 如何在 PrepareForSegue 方法中获取自定义单元格的 indexPath - iOS

标签 ios objective-c uitableview segue nsindexpath

我有一个自定义的 cell,里面只有很少的 View 和按钮。从其中一个按钮,我正在执行 Segue,我需要那个手机号,但不知道如何获得它。请帮忙。

这是我的手机的样子:

enter image description here

prepareForSegue 从红色圆圈按钮调用。

代码如下:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _array.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NewsFeedCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewsFeedCell" forIndexPath:indexPath];
    if (cell) {
        cell.item = _array[indexPath.section];
    }

    return cell;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"AudioComment"])
    {
      NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
        NSLog(@"%ld",(long)indexPath.section); //printing 0 everytime :(
    }
}

请提供有关如何获取 indexPath 的任何帮助/建议?

谢谢。

最佳答案

你可以使用

UITableViewCell *cell = (UITableViewCell *)[[sender superview]superview];
NSLog(@"%ld",(long)[_generalTableView indexPathForCell:cell].row);

关于ios - 如何在 PrepareForSegue 方法中获取自定义单元格的 indexPath - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32629296/

相关文章:

iphone - 如何使用 NSHTTPURLResponse 在 iPhone 上通过 HTTP 查询文件的最后修改日期?

android - Base64 图片上传在 iOS 中不起作用

iphone - 当应用程序进入和退出后台时暂停和恢复核心动画

objective-c - CGContextDrawImage 导致 EXC BAD ACCESS

objective-c - 为什么 init 不是类方法?

iOS:如何推送到 DetailView

ios - 将数据从自定义单元格(在 ViewController 上的表中)传递到 uiviewcontroller 本身 Swift 3 iOS

ios - UITableViewCell 显示点击删除按钮

iphone - 从 XSD 方案生成 objective-c 类,如 Java 中的 JaxB?

swift - 通过 UITabBar 启动相机的最佳方式