gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 18:30:29 25 4
gpt4 key购买 nike

我有一个自定义的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com