views:

346

answers:

0

Hi, why can't I get my programmatically created UIScrollView (or plain UIViews) to sit where I want them?

I am building a viewcontroller component that builds up a uiscrollview and adds it as a subview to placeholder UIView that was dropped in the design using IB.

the main view, with UIView IBOutlet 'ibView' linked to the placeholder view:

- (void)viewDidLoad {
    [super viewDidLoad];
 MyViewController * myViewController = [MyViewController alloc];
 [ibView addSubview:myViewController.view];
}

Loading the scroll view in MyViewController:

- (void)loadView {
    [super loadView];
    CGRect myFrame = self.view.frame;
    myFrame.origin = CGPointZero;
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:myFrame];
    [scrollView addSubview:viewToDisplay];
    [self.view addSubview:scrollView];
}

Results - about 40px white space on top?

http://img195.imageshack.us/img195/928/screenshot20090926at737.png

The placeholder view in IB (search bar is just an example component thrown in to make a smaller view below it):

http://img8.imageshack.us/img8/2833/screenshot20090926at741.png