[英]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.