0

I'm now building up an iPad app which uses UISplitViewController and on the detail view controller I want to initialize two UITableView. However, for some strange reasons even if I tried to initialize those two table views in the same way, only the second table view is initialized properly.

Here's my code that initializes the table views:


_t1 = [[UITableView alloc] initWithFrame:CGRectMake(30, 400, 300, 600)];
_t1.delegate = self;
_t1.datasourse = self;
[self.view addSubview:_t1];

_t2 = [[UITableView alloc] initWithFrame:CGRectMake(360, 400, 300, 600)];
_t2.delegate = self;
_t2.datasourse = self;
[self.view addSubview:_t2];

I set those two table views as @property (strong, nonatomic) in my header file of the view controller. I don't think I've made any mistakes so far.

However, here's the image of the resultant detail view controller. The first table view starts populating its cells after some space is filled at the top of the table view. It looks like the redundant space's height is same to the height of the navigation bar, but when I tried to output self.view before the addSubview: method on the above code, I got the same result saying self.view = <UIView: 0x10a3dd920; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0x10a3dd800>>. So, I think it's added to the same parent view.

enter image description here

So what am I missing? And how can I fix the issue up? I suspect it's related to either navigation controller or split view controller, but am not sure.

I use iOS 7.1 and Xcode 5.1.

Blaszard
  • 30,954
  • 51
  • 153
  • 233

1 Answers1

1

Maybe this will solve your problem

self.automaticallyAdjustsScrollViewInsets = NO;

I'm not sure what is the purpose of that property but it definitely messes a lot of UIScrollViews and UITableViews.

I haven't found a lot of documentation but my theory is that usually you have one uitableview or one uiscrollview as first child of your view. This subview usually takes the whole frame of your view. In that case, i guess you don't have to bother with different topbar (translucent, opaque, ios6). But still that's a lot of assumptions, and i don't think that should be the default behavior.

streem
  • 9,044
  • 5
  • 30
  • 41
  • Thanks. That corrected my problem. But then why does this phenomenon happen? Also, I think I have to define it as property if I want to use it from different methods within the class..., right? – Blaszard Mar 18 '14 at 11:55
  • "I have to define it as property" are you talking about the tableviews ? You could create a property or and an ivar. A property will create a getter and setter and a default ivar. It is better for encapsulation but a bit slower. There is lots of SO questions about it. First one i found : http://stackoverflow.com/questions/843632/is-there-a-difference-between-an-instance-variable-and-a-property-in-objecti – streem Mar 18 '14 at 12:20
  • Yeah, I knew I can define it as ivar, but since property can have getter and setter as well as the variable, I've almost always used property and didn't have any reasons to use ivar (other than the tiny waste of time). – Blaszard Mar 18 '14 at 12:43