I have UITableView that scroll as per expected. I want the table to take up 80% of the space and I want another object at the top. No biggie there. My problem is that I don't want the object at the top to scroll when the table does. Any help/examples of how this can be done would be greatly appreciated. This is seen quite a bit with the search bar. Thanks.
+2
A:
You need to arrange your view hierarchy so the other object is not in a scrollable view. So it should look like the following.
UIView
|
|-- UIView - this one won't scroll
|
|-- UIScrollView
|
|--UITableView
Gary
2010-06-30 02:58:41
Gary,I can see that this works in IB, but when I build, I don't see the items in the second UIView. My apologies for the newb question.
Daniel
2010-06-30 03:41:42
It's a bit difficult to know what's wrong if I can't see your IB project or code sorry.
Gary
2010-06-30 04:13:59
+1
A:
The Gary's answer is good already. I just want to elaborate it.
You have a UIViewControler A (that should not be a UITableVIewController or UIScrollViewController).
Then you have a UITableView B and UIView C.
You can do like this : [A.view addSubview:C]
and then [A.view addSubiew:B]
. Remember to init the view with the correct frame
vodkhang
2010-06-30 03:19:38
Vodkhang,I am a bit confused. Your answer is different than Gary's. Can you elaborate? Thanks for your time.
Daniel
2010-06-30 03:51:45
It is similar, but different explanation, and I use code to do it. You still have the same hierarchy that the main view screen is a UIView, then you add another view A as subview of the main view in the top of the main view. Then you add another UITableView (or UIScrollView) below view A.
vodkhang
2010-06-30 03:58:19
A:
Ok, I got the concept, but now I am lacking the execution. How can I go about adding code in my rootViewControler? I tried the following and I see the two "headers" but they are still both scrolling. I have added them to my viewDidLoad in my RootViewController
UIView *containerViewA =
[[[UIView alloc]
initWithFrame:CGRectMake(0, 0, 300, 60)]
autorelease];
UIView *containerViewB =
[[[UIView alloc]
initWithFrame:CGRectMake(10, 60, 300, 60)]
autorelease];
UILabel *headerLabelA =
[[[UILabel alloc]
initWithFrame:CGRectMake(10, 20, 300, 40)]
autorelease];
UILabel *headerLabelB =
[[[UILabel alloc]
initWithFrame:CGRectMake(10, 80, 300, 40)]
autorelease];
headerLabelA.textColor = [UIColor whiteColor];
headerLabelA.shadowColor = [UIColor blackColor];
headerLabelA.shadowOffset = CGSizeMake(0, 1);
headerLabelA.font = [UIFont boldSystemFontOfSize:22];
headerLabelA.backgroundColor = [UIColor clearColor];
headerLabelA.text = NSLocalizedString(@"A", @"");
headerLabelB.textColor = [UIColor whiteColor];
headerLabelB.shadowColor = [UIColor blackColor];
headerLabelB.shadowOffset = CGSizeMake(0, 1);
headerLabelB.font = [UIFont boldSystemFontOfSize:22];
headerLabelB.backgroundColor = [UIColor clearColor];
headerLabelB.text = NSLocalizedString(@"B", @"");
[containerViewB addSubview:headerLabelA];
[containerViewA addSubview:containerViewB];
[self.view addSubview:containerViewA];
Daniel
2010-07-01 21:20:38