从 UIButton 发件人返回了错误的 tableViewCell
Wrong tableViewCell being returned from UIButton sender
对于 ios 7 和更大的部分,返回的单元格始终是第一个单元格,即 indexpath.row =0。尽管我考虑了带有额外 .superview.
的单元格内部的滚动视图
- (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's
convertPoint:toView
method
得到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 7 和更大的部分,返回的单元格始终是第一个单元格,即 indexpath.row =0。尽管我考虑了带有额外 .superview.
的单元格内部的滚动视图- (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's
convertPoint:toView
method
得到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
}