In a current project I came across the situation that I wanted to implement a cool TTScrollView with a few TTTableViews in it.
For some reason in my version of the current Three20 branch the TableView was receiving the “up and down” touch events but the parent view (TTSscrollView) didn’t get any touch events. Googeling give me the result that some of you had the same problem but I couldn’t find any solution for the problem.
So I came up with the following solution for the problem.
I added a new category TTTableView+TouchesMoveAddition:
// UI
#import "Three20UI/TTNavigator.h"
#import "Three20UI/TTStyledTextLabel.h"
#import "Three20UI/UIViewAdditions.h"
// UICommon
#import "Three20UICommon/UIWindowAdditions.h"
// Style
#import "Three20Style/TTStyledNode.h"
#import "Three20Style/TTStyledButtonNode.h"
#import "Three20Style/TTStyledLinkNode.h"
// Core
#import "Three20Core/TTCorePreprocessorMacros.h"
#import "TTTableView+TouchesMovedAddition.h"
@implementation TTTableView (TTTableViewDataSourceNIBCapAddition)
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
[super touchesBegan:touches withEvent:event];
if ([self.delegate respondsToSelector:@selector(tableView:touchesMoved:withEvent:)]) {
id<TTTableViewDelegate> delegate = (id<TTTableViewDelegate>)self.delegate;
[delegate tableView:self touchesMoved:touches withEvent:event];
}
if (_highlightedLabel) {
UITouch* touch = [touches anyObject];
_highlightStartPoint = [touch locationInView:self];
}
}
@end
So if you implement the UITableView protocol in your ViewController which holds, for example, your TTScrollView:
- (void)tableView:(UITableView*)tableView touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
tableView.scrollEnabled = NO;
[_scrollView touchesBegan:touches withEvent:event];
}
- (void)tableView:(UITableView*)tableView touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{
[_scrollView touchesMoved:touches withEvent:event];
}
- (void)tableView:(UITableView*)tableView touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{
tableView.scrollEnabled = YES;
[_scrollView touchesEnded:touches withEvent:event];
}
The touch events will be forwarded to the TTScrollView.
Focus on the scrollEnable calls !!!… 🙂
have fun 🙂