문제

프로그래밍 방식으로 두 개의 사용자 정의 UIPICKERViews를 다른보기 (MainView)에 추가합니다. 그들은 잘 작동하지만 메인 뷰의 어느 부분에서나 터치 이벤트가 발생할 때까지 보이지 않습니다. UIPICKERVIEW 및 UIVIEW에 대한 클래스 참조를 확인했지만 명백한 것을 놓치지 않는 한보기를 "새로 고침"할 수있는 것을 찾지 못했습니까?

MainView.m의 DrawRect 메소드는 다음과 같습니다. 나는 ViewDidload에서 같은 일을 시도했지만 성공하지 못했습니다. 사용자 정의 회전/변환 등이 그것과 관련이있을 수 있습니까?

- (void)drawRect:(CGRect)rect { 
    CGRect pickerFrame = CGRectMake(50, -32, 30, 180);
    m_picker1 = [[UIPickerView alloc] initWithFrame:pickerFrame];
    m_picker1.delegate = self;  
    m_picker1.tag = k_ptag1;
    m_picker1.showsSelectionIndicator =YES;  
    m_picker1.backgroundColor = [UIColor clearColor]; 
    CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);  
    rotate = CGAffineTransformScale(rotate, 0.075, 0.85);  
    [m_picker1 setTransform:rotate];  
    [self addSubview:m_picker1]; 

    pickerFrame = CGRectMake(50, 67, 30, 180);
    m_picker2 = [[UIPickerView alloc] initWithFrame:pickerFrame];
    m_picker2.delegate = self;  
    m_picker2.tag = k_ptag2;
    m_picker2.showsSelectionIndicator =YES;  
    m_picker2.backgroundColor = [UIColor clearColor]; 
    rotate = CGAffineTransformMakeRotation(3.14/2);  
    rotate = CGAffineTransformScale(rotate, 0.075, 0.85);  
    [m_picker2 setTransform:rotate];  
    [self addSubview:m_picker2];
}
도움이 되었습니까?

해결책

보기 자체가 아닌보기 컨트롤러에 서브 뷰를 추가합니다. MVC 디자인 패턴에 익숙해지는 것이 좋습니다.

DrawRect는 하위 뷰가 아닌보기 자체의 실제 도면에만 사용됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top