我创建了一个带有 UIScrollView 的 UIViewController。在 scrollView 我有一个页面控件。当我测试它时,我能够水平滚动浏览四个不同颜色的页面。现在我需要添加我需要的实际视图。在项目的不同部分,我使用 coreplot 创建了一个折线图。现在我添加了一个新的 UIview 并添加了折线图的代码。我现在正在尝试用线图 UIView 替换滚动视图的第一页。我没有收到任何错误,但屏幕上也没有出现任何错误。它只是滚动视图的默认背景。scrollView 仍然可以正确滚动其他页面。我以编程方式向 UIView 添加了一个按钮,以查看它是否与 coreplot 有关,但我也看不到。这是我的一些代码。我会很感激任何建议。谢谢。
我的主视图控制器的 viewDidLoad 方法: - (void)viewDidLoad { [super viewDidLoad];
    NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor],     [UIColor blueColor], [UIColor purpleColor], nil];
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
    self.alertsSubView = [[AlertsView alloc] initWithFrame:frame];
    [self.scrollView addSubview:_alertsSubView];
    for (int i = 1; i < numberOfGraphs; i++) {
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
        UIView *subview = [[UIView alloc] initWithFrame:frame];
        subview.backgroundColor = [colors objectAtIndex:i];
       [self.scrollView addSubview:subview];
        self.alertsSubView.delegate = self;
    _scrollView.delegate = (id)self;
    }
    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count,   self.scrollView.frame.size.height);
}
这是我的 UIView 中的 initWithFrame 方法的代码。所有的 NSLog 语句都会运行,所以我知道所有的东西都被调用了:
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        NSLog(@"AlertsView initWithFrame");
        ///button for testing
        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        CGRect buttonFrame = CGRectMake(0,0, frame.size.width, frame.size.height);
        self.button.frame = buttonFrame;
        [self.button addTarget:self
                        action:@selector(buttonTouched)
              forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.button];
        [self initPlot];
    }
    return self;
}
我还添加了方法 initPlot 和 ConfigureHost 以防它们相关:
-(void)initPlot {
    NSLog(@"into init plot");
    [self configureHost];
    [self configureGraph];
    [self configurePlots];
    [self configureAxes];
    NSLog(@"endo of init plot");
}
-(void)configureHost {
    NSLog(@"into configure host");
    self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc]         initWithFrame:self.bounds];
    self.hostView.allowPinchScaling = YES;
    [self addSubview:self.hostView];
}