将分享如何解决这个问题。将 UIScrollView 子类化并用作 PlaceDetailsViewController 中的容器视图:
@interface PlaceDetailsContainerUIScrollView : UIScrollView
@end
@implementation PlaceDetailsContainerUIScrollView
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *result = [super hitTest:point withEvent:event];
if ([result isKindOfClass:[UIView class]] && (result.tag == kDiscountListTableViewCellTag)
{
UITableView *tableView = (UITableView *) [[result.superview superview] superview];
return tableView;
}
return result;
}
@end
另外,不要忘记设置 PlaceDetailsContainerUIScrollView.delaysContentTouches = YES 和 PlaceDetailsContainerUIScrollView.canCancelContentTouches = NO。
此外,需要在 DiscountListTableViewController 方法中进行小修复:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DiscountDetailsViewController *discountDetailsVC = [[DiscountDetailsViewController alloc] init];
//[self.navigationController pushViewController:discountDetailsVC animated:YES];
// self.navigationController is nill because it's not pushed on nav stack, so will grab the current one:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController pushViewController:discountDetailsVC animated:YES];
}