我有一个自定义的 cell
,里面只有很少的 View 和按钮。从其中一个按钮,我正在执行 Segue
,我需要那个手机号,但不知道如何获得它。请帮忙。
这是我的手机的样子:
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/