gpt4 book ai didi

ios - 从 UIButton 发件人返回了错误的 tableViewCell

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

对于 ios 7 和更大的部分,返回的单元格始终是第一个单元格,即 indexpath.row =0。尽管我考虑了带有额外 .superview 的单元格内部的 ScrollView 。

- (UITableViewCell *)getCellforButton:(UIButton *)sender
{
UITableViewCell *cell;

//Check for iOS version and get the cell accordingly
NSArray *versionComponenets = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];

if ([[versionComponenets objectAtIndex:0] intValue] >= 7)
{
// iOS-7 code[current] or greater
//Additional superview call to account for new scrollview inside of cells
cell = (UITableViewCell *)sender.superview.superview.superview;
}
else
{
// iOS-6 code
cell = (UITableViewCell *)sender.superview.superview;
}

return cell;
}

最佳答案

使用 UIView 的 convertPoint:toView 方法 获取 UITableViewCell

-(UITableViewCell *)getCellforButton:(UIButton *)sender
{
CGPoint btnPosition = [sender convertPoint:CGPointZero toView:yourTableViewHere];
NSLog(@"btnPositionn : %@",NSStringFromCGPoint(btnPosition));
NSIndexPath *curIndexPath = [yourTableViewHere indexPathForRowAtPoint:btnPosition];
id cell = [yourTableViewHere cellForRowAtIndexPath:curIndexPath];
if (cell)
{
UITableViewCell *curCell = cell;
return curCell;
}
else
return nil
}

关于ios - 从 UIButton 发件人返回了错误的 tableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29630707/

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