5

I am adding a TTTableViewController into an existing UIViewController, one strange thing I found is that the frame properties of the initialized TTTableViewController are wired, e.g. in a iOS layout.

I have:

  1. UIStatusBar
  2. UINavigationController
  3. UIViewController
  4. UITabBar

In order to set the TTTableViewController fill in all the remaining space I need to set the height to 460 instead of 367. (367 = 480-20-44-49)

e.g.

self.tableViewController.view.frame = CGRectMake(0, 0, 320, 460.0f);

instead of

self.tableViewController.view.frame = CGRectMake(0, 0, 320, 367.0f);

Why is it so?

*Edit for clarification: I mean TTTableViewController on the top of TTViewController (using [self.view addSubview:self.tableViewController.view];), and I need to set the self.tableViewController.view.frame = CGRectMake(0, 0, 320, 460.0f); instead of 367

SkylerHill-Sky
  • 2,106
  • 2
  • 17
  • 33
Ryan
  • 10,041
  • 27
  • 91
  • 156
  • what do you mean that you add a `TTTableViewController` into a controller? can you provide us with the source code? – aporat Sep 18 '12 at 19:10
  • @aporat, I mean add `TTTableViewController` on the top of `TTViewController` (using `[self.view addSubview:self.tableViewController.view];`), and I need to set the `self.tableViewController.view.frame = CGRectMake(0, 0, 320, 460.0f);` instead of `367` – Ryan Sep 19 '12 at 10:46

4 Answers4

2

It depends on when you are setting the frame, I think. I'm pretty sure when you set the frame in viewDidLoad, for example, you'll be setting it before the status bar and other things are taken into account. There might be other cases like this. If you set it to 320:460, it'll be resized to take into account the status bar and other stuff afterwards, making it fill in the rest of the screen. If you set it to 320:367 because you've already taken into account that stuff, it'll get resized again and squished (basically scaled down twice), making it only fill part of the screen. If you're using viewDidLoad you could try sticking it in another method (maybe viewWillAppear?) or just keep using 320:460.

It'd be nice to know when you set the frame, exactly. Also keep in mind that I could be way off. My mind's feeling a little fuzzy right now.

Metabble
  • 11,773
  • 1
  • 16
  • 29
  • Good question, I load it from `loadView` and after `[super loadView];` – Ryan Sep 21 '12 at 11:29
  • Well, looking at the documentation, it says you _shouldn't_ call [super loadView]. Although I'm guessing you do so here to instantiate and set self.view so you can add a subview. Better to do that yourself, probably. Also, let me get this straight: when loadView is called you add tableViewController's view as your own subview? Apple's documentation also says not to add any views in this method which are shared with other view controllers: only unique views. Adding a view from another controller seems to violate this. Consider doing this in another spot if you can, or set the frame elsewhere. – Metabble Sep 21 '12 at 15:53
  • my view controller extend from three20 view controller so `[super loadView]` is needed. – Ryan Sep 28 '12 at 04:02
  • Yeah, I can see how it would be. My only advice would be to do whatever works (in this case, 320:460), or move the code to another spot. That's about it. :/ – Metabble Sep 28 '12 at 16:56
2

As per my understanding, only the size of your status bar is deducted i.e. 480-20 = 460. actually status bar is 22 pts but its approx.

Its just like when you add a viewcontroller to your navigation controller or your tab bar controller the size is auto rendered. So same is the case here, the three20 automatically adjusts the size of the view and if you try to set it to something smaller then that it behaves differently.

Its a nice question though. Happy Coding. Cheers!!

Apple_iOS0304
  • 1,092
  • 1
  • 9
  • 19
  • Yes, if I am replacing the `TTTableViewController` by an `UIView` then I need to init the frame using `CGRectMake(0, 0, 320, 367.0f);` – Ryan Sep 21 '12 at 11:31
1

I wouldn't add a view of a different view controller into the main view of your current view.

You should present the TTTableViewController using the controller's present / dismiss functions. if you don't want to include the slide up effect, so the users won't see that it's a "different screen", use the boolean flag when you present the controller.

   [self presentModalViewController:vc animated:NO];

Alternatively, use a TTTableView without the controller:

tableView = [[TTTableView alloc] initWithFrame:CGRectMake(0, kScrollViewHeight + kSignupLabelHeight, 320, kTableViewHeight) style:UITableViewStyleGrouped];
[tableView setBackgroundColor:[UIColor clearColor]];

tableView.delegate = self;
tableView.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                                 @"",
                                 [TTTableTextItem itemWithText:@"Sign Up" URL:@"tt://signupController"],
                                 nil];
[self.view addSubview:tableView];
aporat
  • 5,922
  • 5
  • 32
  • 54
0

Like a this code . if use iOS6 , get current device. if();

-(void)viewdidLoad{

TTTableViewController *tt = [TTTableViewController new]; CGRect frame = [UIScreen mainScreen].bounds; tt.frame = frame; tt.delegate = self;

[self.view addsubview:tt];

}

rbbtsn0w
  • 75
  • 11