0

我正在使用 UIScrollView 进行分页,我注意到我分页的后续视图都没有调用它们的数据源/委托。我将它作为数据源/委托连接到他们的 XIB 中,并在代码中以这种方式设置它,但它仍然没有被调用。

我猜问题出在这里......我在哪里进行分页并插入第二和第三个视图。委托/数据源都不能处理被分页的第二个或第三个视图。

requestDetailTwoViewController *controller = [viewControllers objectAtIndex:1];

requestDetailThreeViewController *controller2 = [viewControllers objectAtIndex:2];
if ((NSNull *)controller == [NSNull null])
{
    if(page == 1)
    {

        controller = [[requestDetailTwoViewController alloc] initWithRequestNumber:[request objectForKey:@"RequestID"] forID:self.employeeIDfromHome];
        [viewControllers replaceObjectAtIndex:page withObject:controller];
        CGRect frame = scrollView.frame;
        frame.origin.x = frame.size.width * 1;
        frame.origin.y = 0;
        controller.view.frame = frame;
        [scrollView addSubview:controller.view];
    }
}

if ((NSNull *)controller2 == [NSNull null])
{
    if(page == 2)
    {
        controller2 = [[requestDetailThreeViewController alloc] initWithRequestNumber:[request objectForKey:@"RequestID"]];
        [viewControllers replaceObjectAtIndex:page withObject:controller2];
        [self addChildViewController:controller2];
        CGRect frame = scrollView.frame;
        frame.origin.x = frame.size.width * 2;
        frame.origin.y = 0;
        controller2.view.frame = frame;
        [scrollView addSubview:controller2.view];
        [controller2 didMoveToParentViewController:self];
    }

}

谢谢!

4

1 回答 1

0

在您的班级中,您是否为协议设置了提示,例如

@interface myClass : UIViewController <UIScrollViewDelegate> {
...

后来,在你的viewDidLoad

self.myScrollView.delegate = self;
于 2012-10-02T15:59:54.993 回答