iPhone object not to be scrollable
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.
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开发者_Go百科 = [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];
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
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
精彩评论