خرید بک لینک

Vote count: 0

I created my own freeform first view controller and placed a table view inside of it. I set its class properly and created an IBOutlet for this table.

In my second view controller I want to display the view from first view controller as a slide in window, so I created and IBAction that will do this:

- (IBAction)optionsButtonTapped:(id)sender {
    OptionsViewController *optionsVC = [[OptionsViewController alloc] init];

    // Custom CGRect:
    CGFloat width = self.view.frame.size.width - 10.0;
    CGFloat height = [optionsVC.optionsTableView numberOfRowsInSection: 0] * 50.0;
    CGFloat x = self.view.frame.origin.x + ((self.view.frame.size.width - width) / 2);
    CGFloat y = self.view.frame.origin.y + self.view.frame.size.height + (1.2 * height);
    CGRect hiddenFrame = CGRectMake(x, y, width, height);

    // Custom UIView:
    UIView *view = optionsVC.view;
    view.frame = hiddenFrame;
    [self.view addSubview: view];
    [self addChildViewController: optionsVC];
    [optionsVC didMoveToParentViewController: self];
    //NSLog(@"Frame for the view is: %@", NSStringFromCGRect(hiddenFrame));

    // Animation:
    [UIView animateWithDuration: 0.3 animations:^(void){
        CGRect visibleFrame = hiddenFrame;
        visibleFrame.origin.y = self.view.frame.origin.y + self.view.frame.size.height - 5.0 - height;
        view.frame = visibleFrame;
    } completion:^(BOOL finished) {
        NSLog(@"Animation completed");
    }];
}

The height when I use NSLog is 0, that is because the tableview is not being loaded when I init optionsVC (I set up the dataSource and delegate). Even if I set the height to eg. 200.0 the view still does not appear, however I have a log from second view controller that viewDidLoad was performed.

What am I doing wrong?

asked 18 secs ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 30 تير 1395 ساعت: 20:05

صفحه بندی