繁体   English   中英

UITableView的IndexPath不起作用

[英]IndexPath for UITableView Not Working

我正在尝试确定我的UITableView的选择行的indexPath ,以便我可以相应地传递相关数据。 现在,无论我选择哪个单元格,它都会记录0 有什么想法吗? (是的,表的IBOutlet正确连接)。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"patientChart"])
    {
        UITabBarController *tabBar = (UITabBarController *)segue.destinationViewController;
        PatientChartViewController *vc = [tabBar.childViewControllers objectAtIndex:0];
        NSIndexPath *path = [self.appointmentTableView indexPathForSelectedRow];
        vc.appointmentDictionary = [self.appointmentArray objectAtIndex:path.row];
    }
}

如果选择了行,则方法indexPathForSelectedRow将返回所选行的索引,否则返回0。

因此,例如,如果已选择cell并稍后取消选择,则不会通过调用[tableView indexPathForSelectedRow];获取其index path [tableView indexPathForSelectedRow]; 因为那时没有选择任何一个单元格。

如果使用iOS5,则解决方法是在.h中声明一个实例并将属性设置为copy,如下所示。

NSIndexPath *path;
@property (nonatomic, copy) NSIndexPath *path;

将indexpath值分配给实例,即cellForRowAtIndexPath方法中的路径。

尝试在iOS5上执行此操作时遇到此问题,并按上述方法解决此问题。 希望这对你有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM