tags:

views:

402

answers:

1

I have an application which contains a scrollview with two subviews (to scroll left and right between them)

Both views appear correctly and scrolling between the views worked fine. Now I want to change the first view to be a TTTableView (courtesy of Three20) but when I use the class 'TableControlsTestController' from the TTCatalog application all I see is an empty tableView

Note that this class contains all the data to display 6 cells

To add the new TTTableView I use the following

 [scrollView addSubview:detailView.view];

where detailView is the instance of TableControlsTestController

To try and narrow down where the problem is I also tried calling

[self presentModalViewController:detailView animated:YES];

This correctly displays the tableview with the 6 cells.

Why when I try to add the view to the scrollView does this not work as I expect?


For reference if you do not have access to the TTCatalog

#import "TableControlsTestController.h"

///////////////////////////////////////////////////////////////////////////////////////////////////

@implementation TableControlsTestController

///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject

- (id)init {
  if (self = [super init]) {
    self.tableViewStyle = UITableViewStyleGrouped;
    self.autoresizesForKeyboard = YES;
    self.variableHeightRows = YES;

    UITextField* textField = [[[UITextField alloc] init] autorelease];
    textField.placeholder = @"UITextField";
    textField.font = TTSTYLEVAR(font);

    UITextField* textField2 = [[[UITextField alloc] init] autorelease];
    textField2.font = TTSTYLEVAR(font);
    textField2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    TTTableControlItem* textFieldItem = [TTTableControlItem itemWithCaption:@"TTTableControlItem"
                                                            control:textField2];

    UITextView* textView = [[[UITextView alloc] init] autorelease];
    textView.text = @"UITextView";
    textView.font = TTSTYLEVAR(font);

    TTTextEditor* editor = [[[TTTextEditor alloc] init] autorelease];
    editor.font = TTSTYLEVAR(font);
    editor.backgroundColor = TTSTYLEVAR(backgroundColor);
    editor.autoresizesToText = NO;
    editor.minNumberOfLines = 3;
    editor.placeholder = @"TTTextEditor";

    UISwitch* switchy = [[[UISwitch alloc] init] autorelease];
    TTTableControlItem* switchItem = [TTTableControlItem itemWithCaption:@"UISwitch" control:switchy];

    UISlider* slider = [[[UISlider alloc] init] autorelease];
    TTTableControlItem* sliderItem = [TTTableControlItem itemWithCaption:@"UISlider" control:slider];

    self.dataSource = [TTListDataSource dataSourceWithObjects:
      textField,
      editor,
      textView,
      textFieldItem,
      switchItem,
      sliderItem,
      nil];
  }
  return self;
}

@end
+2  A: 

It turns out that some of the events were not being propagated through the scrollView and therefore not handled in the TTTableViewController. To fix this I had to do the following in my scrollView

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [myNewTTViewController viewWillAppear:NO];
}


- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  [myNewTTViewController viewDidAppear:NO];
}

- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  [myNewTTViewController viewWillDisappear:NO];
}

- (void)viewDidDisappear:(BOOL)animated {
  [super viewDidDisappear:animated];
  [myNewTTViewController viewDidDisappear:NO];
}

As soon as I did this the table popped into life

Liam
I was having this problem, too. Thanks, Liam.
thebossman
Me too. I don't know how I would have figured this out on my own. Thanks man.
Paul Shapiro