0

UIScrollView を使用して UIViewController を作成しました。scrollView には、ページ コントロールがあります。テストしていたとき、4 つの異なるカラー ページを水平方向にスクロールできました。次に、必要な実際のビューを追加する必要があります。プロジェクトの別の部分で、coreplot を使用して折れ線グラフを作成しました。ここで、新しい UIview を作成し、折れ線グラフのコードを追加しました。現在、scrollView の最初のページを線グラフ UIView に置き換えようとしています。エラーは発生しませんが、画面にも何も表示されません。これは、scrollView のデフォルトの背景です。scrollView は、他のページを正しくスクロールします。プログラムでUIViewにボタンを追加して、coreplotと関係があるかどうかを確認しましたが、それもわかりません。これが私のコードの一部です。アドバイスをいただければ幸いです。ありがとう。

メイン viewController の 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];
}
4

1 に答える 1

0

私はついにこれを理解しました。あなたの提案をありがとう@Eric Skroch。それは問題ではありませんでしたが、実際には正しい答えへの道をたどりました。基本的に、この問題を修正するには、すべてのロジックをビュー コントローラーに移動し、多くのコードの順序を変更する必要がありました。誰かが似たようなものに出くわした場合に備えて、改訂したView Controllerの関連部分をここに投稿しています。

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [_alertsSubView initPlot];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor],   [UIColor blueColor], [UIColor purpleColor], nil];
    alertFrame.origin.x = self.scrollView.frame.size.width;
    alertFrame.origin.y = 0;
    alertFrame.size = self.scrollView.frame.size;
    _panel = [[UIView alloc]initWithFrame:alertFrame];

    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.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
    _scrollView.delegate = (id)self;
    self.alertsSubView.delegate = self;
}
-(AlertsView *)alertsSubView
{
    if(!_alertsSubView)
    {
        CGRect alertsViewFrame = CGRectMake(0,0, _panel.bounds.size.width,     _panel.bounds.size.height);
        _alertsSubView = [[AlertsView alloc] initWithFrame:alertsViewFrame];
        _alertsSubView.backgroundColor = [UIColor purpleColor];
        [self.scrollView addSubview:self.alertsSubView];
    }
    return _alertsSubView;
}
于 2013-05-24T19:10:59.497 に答える