2013-05-23 2 views
0

UIScrollView를 사용하여 UIViewController를 만들었습니다. scrollView에는 페이지 컨트롤이 있습니다. 테스트 할 때 4 가지 색상 페이지를 가로로 스크롤 할 수있었습니다. 이제 필요한 실제 뷰를 추가해야합니다. 이 프로젝트의 다른 부분에서는 coreplot을 사용하여 선 그래프를 만들었습니다. 이제 새로운 UIview를 추가하고 선 그래프의 코드를 추가했습니다. scrollView의 첫 번째 페이지를 선 그래프 UIView로 바꾸려고합니다. 그러나 아무런 오류도 나타나지 않고 화면에 아무 것도 나타나지 않습니다. 이것은 scrollView의 기본 배경 일뿐입니다. scrollView 여전히 다른 페이지를 올바르게 스크롤합니다. 프로그래밍 방식으로 UIView에 단추를 추가하여 coreplot과 관련이 있는지 확인했지만 그 중 하나를 볼 수 없습니다. 여기 내 코드 중 일부입니다. 나는 어떤 조언을 주셔서 감사하겠습니다. 감사.Xcode - 하위보기가 표시되지 않습니다.

내 주의 ViewController viewDidLoad에 대한 방법 : - (공극)이있는 viewDidLoad {[슈퍼의 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 메소드 코드입니다. 나는 또한 경우에 방법 initPlot 및 ConfigureHost를 추가하고

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

가 관련된 :

-(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]; 
} 
+0

플롯 데이터 소스가 호출 되나요? 그렇지 않은 경우 다른 구성 방법 중 하나에서 구성 문제가있을 가능성이 큽니다. –

+0

플롯 데이터 소스가 호출됩니다. 내가 UIViewController에서 실험 할 때 모든 것을 표시했습니다. 그것만이 이제는 코드를 UIView로 옮겼고이 문제를 가지고있는 하위 뷰로 UIScrollView에 추가하려고합니다. 나는 모든 것을 정확히 복사했다. 유일한 차이점은 'initPlot'은 viewDidAoear : VC의 원래 버전에서 움직이는 것입니다. 이제는 UIView에 가지고 있는데, viewDidAppear은 UIView 메서드가 아니기 때문에 initWithFrame으로 옮겨야했습니다. – MichelleJS

+0

'- (void) viewDidAppear : (BOOL) animated { [super viewDidAppear : animated]; [_alertsSubView initPlot]; NSLog (@ "viewDidAppear - statsvc"); } '나는 이것을 vc에 추가하려고 시도했지만 화면에는 아무것도 표시되지 않는다. 하위 뷰에 설정 한 배경색조차도 표시되지 않습니다. – MichelleJS

답변

0

나는 마침내 알아 낸 NSLog 문은 모두 내가 다가 호출되고 알 수 있도록 실행하세요. 귀하의 제안에 감사드립니다 @ 에릭 Skroch. 그것이 실제로 문제가 아니었지만 실제로 저를 올바른 답으로 이끌었습니다. 기본적으로이 문제를 해결하기 위해 모든 논리를보기 컨트롤러로 옮기고 코드의 순서를 변경해야했습니다. 아무도 비슷한 것을 발견 할 경우에 대비하여 여기에서 수정 된 뷰 컨트롤러의 관련 부분을 게시하고 있습니다.

-(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; 
} 
관련 문제