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];
}