gpt4 book ai didi

ios - 尝试获取 UITableViewCell 的 indexPath 时出现错误

转载 作者:行者123 更新时间:2023-11-28 21:48:44 25 4
gpt4 key购买 nike

我在我的 UITableViewCell 中添加了一个 UIButton,在该按钮的操作中,我添加了以下代码以获取单元格的 indexPath。但它一直返回错误 - 'NSInvalidArgumentException',原因:'-[UITableViewCell indexPathForCell:]:无法识别的选择器发送到实例 0x7cea3fc0'

谁能告诉我这里要做什么?

- (IBAction)navigateMap:(id)sender {
__strong UIButton *button=(UIButton *) sender;
UITableViewCell *cell = (UITableViewCell *)button.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
//rest of the logic
}

完整代码

- (IBAction)navigateMap:(id)sender {
__strong UIButton *button=(UIButton *) sender;
UITableViewCell *cell = (UITableViewCell *)button.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
CombinedStations *inButton=[[CombinedStations alloc] init];
inButton=[_finalStationList objectAtIndex:indexPath.section];
_universalRegion->center.latitude=inButton.latitude;
_universalRegion->center.longitude=inButton.longitude;
NSString *launchUrl=@"";
launchUrl= [launchUrl stringByAppendingString:@"http://maps.google.com/maps?daddr="];
NSString *tmpLat = [[NSString alloc] initWithFormat:@"%f", _universalRegion->center.latitude];
NSString *tmpLong = [[NSString alloc] initWithFormat:@"%f", _universalRegion->center.longitude];
NSString *llat=[tmpLat stringByAppendingString:[@"," stringByAppendingString:tmpLong]];
launchUrl=[@"http://maps.google.com/maps?daddr=" stringByAppendingString:llat];
launchUrl=[launchUrl stringByAppendingString:[@"&saddr=" stringByAppendingString:@"Current Location"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[launchUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

最佳答案

试试这个,这将是获取表的索引路径的非常简单的方法。

- (IBAction)navigateMap:(id)sender {

CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:tableViewName];
NSIndexPath *indexPath = [tableViewName indexPathForRowAtPoint:buttonPosition];
}

关于ios - 尝试获取 UITableViewCell 的 indexPath 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29097504/

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