Three20 how to use TTTableView within TTScrollView addition

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 🙂

11 thoughts on “Three20 how to use TTTableView within TTScrollView addition”

    1. Hi Dio,

      If you can give me more detailes about you problem?. Do you mean that the tableview is never receiving any touch events ?

      1. Okay, just found what cause this problem when I comment the line ‘tableView.scrollEnabled = NO/YES;’ .

        But I have another problem, TTTableView will receive the touchbegan: event delay. not immediately when I touch on the TTTableView, it’s the normal behaviour?

        You can find me via msn: zzy_moon@hotmail.com
        Thanks in advance!

        1. Hi Dio,

          Maybe you have the “delaysContentTouches” set to “YES” for your scrollview? The default value of this property is “YES”

  1. Hi Mario, thanks for the solution, which works great. However, if we add TTModel/TTDataSource (for remote resources) support, the table view get delays from the very first page. Even worst, after first round paging, the table view get totally lost. Not sure if you have met this b4, any help will be appreciated. Thanks again.

    1. Hi Jim,

      Have you implemented all three protocols?,

      – (void)tableView:(UITableView*)tableView touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
      ////////////////////////////////////////////////////////////////////////////////////////////////
      – (void)tableView:(UITableView*)tableView touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
      ///////////////////////////////////////////////////////////////////////////////////////////////////
      – (void)tableView:(UITableView*)tableView touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event

      You could also add “tableView.scrollEnabled =NO;” to “touchesBegan” respectivley “tableView.scrollEnabled =YES;” to “touchesEnded”.
      Maybe your parent scrollView has “delaysContentTouches” set?

      Mario

      1. Hi Mario, tks for the quick response. And yes, I did implement all these three methods from TTTableViewDelegate as you stated above, beside, seems TTScrollView does not provide “delaysContectTouches” as UIScrollView does.

        Sorry I didn’t make it clear enough in previous question, actually regular UITableView/TTTableView already works well under TTScrollView, but when it comes to TTModel/TTTableViewDataSource, no luck then. Though data get loaded correctly, the main table view get lost…

        1. Hi Jim,

          Hmmm, is difficult to diagnose without to have a look at your source. If you want you can send me the related source parts.

          1. Hi Mario, I’ve double checked the code, I think the only difference is that I didn’t implement the TTTableView category as you stated, since I got everything running smooth so I wondered if the category is really necessary. As the TTModel/TTTableViewDataSource also involve delegate of the table view, I think it might be the problem. Anyway, I’ll give some tries tmr & get back to you later. Thanks for the helps.

            Beside, Is there any way I can send you some code for sharing?

          2. Hi Mario, I think I found the issue, and it’s not abt the delegate. I was trying to use the same & the only tableView instance from the TTTableViewController, no luck. I happened to create a new table view instance with the same datasource, everything works as expected then. I guess this’s the way scrolling needed to be. Thanks for your helps anyway 🙂

Leave a Reply to Jim Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.