2012-08-27 3 views
0

두 개의 하위보기를 설정 한 ViewController가 있습니다. 나는 그들 사이를 토글하고 싶다. 그러나 내 StepOne보기 내의 버튼이 트리거되지 않습니다.UIView (ViewControllers보기의 하위보기) UIButton은 클릭 이벤트를받을 수 없습니다.

올바른 방식으로보기를 사용하고 있습니까? 클릭 이벤트를 수신하려면 어떻게해야합니까?

감사

@interface UsageAlertsViewController() 

@end 

@implementation UsageAlertsViewController 

@synthesize currViewNum, stepOneView, stepTwoView; 

int padSides = 15; 
int summaryViewNum =99, stepOneViewNum = 1, stepTwoViewNum = 2; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self initAlerts]; 
} 

-(void) initAlerts 
{ 
    [self initViews]; 
    [self setCurrentView]; 
    [self gotoView]; 
} 

-(void) initViews 
{ 
    stepOneView = [[UIView alloc] init]; 
    stepTwoView = [[UIView alloc] init]; 
    stepOneView.userInteractionEnabled = NO; 
    stepTwoView.userInteractionEnabled = NO; 
    [self.view addSubview: stepOneView]; 
    [self.view addSubview: stepTwoView]; 
} 

-(void) showSummary 
{ 
    NSLog(@"showing summary"); 
} 

-(void) showStepOne { 
    NSLog(@"showing step one"); 

    //Intro label 
    int introLabelWidth = 200; 
    int introLabelHeight = 30; 
    int introLabelXPos = [GeneralHelper GetCenteredXPosForObj:introLabelWidth :self.view]; 
    int introLabelYPox = [GeneralHelper TopPadding] + 50; 
    UILabel *introLabel = [[UILabel alloc] initWithFrame:CGRectMake(introLabelXPos, introLabelYPox, introLabelWidth, introLabelHeight)]; 
    introLabel.text = @"Get alerts on the go!"; 
    introLabel.backgroundColor = [UIColor clearColor]; 
    introLabel.font = [UIFont boldSystemFontOfSize:20]; 
    introLabel.textColor = [[Global get] orangeClr]; 
    [self.stepOneView addSubview:introLabel]; 

    //Intro text 
    int introTVWidth = self.view.frame.size.width - (2*padSides); 
    int introTVHeight = 1; 
    int introTVXPos = [GeneralHelper GetCenteredXPosForObj:introTVWidth :self.view]; 
    int introTVYPox = 115; 
    UITextView* introTextView = [[UITextView alloc] initWithFrame:CGRectMake(introTVXPos, introTVYPox, introTVWidth, introTVHeight)]; 
    introTextView.backgroundColor = [UIColor clearColor]; 
    introTextView.font = [UIFont systemFontOfSize:15]; 
    introTextView.textAlignment = UITextAlignmentCenter; 
    NSString* tx = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"alertsIntroStep1" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil]; 
    introTextView.text = tx; 
    introTextView.editable = false; 
    introTextView.scrollEnabled = false; 
    [self.stepOneView addSubview:introTextView]; 
    [GeneralHelper resizeTextView:introTextView]; 

    //Intro button 
    int nextButtonWidth = 75; 
    int nextButtonHeight = 35; 
    int nextButtonXPos = [GeneralHelper GetCenteredXPosForObj:nextButtonWidth :self.view]; 
    int nextButtonYPos = 340; 
    UIButton *next = [OrangeButton Create:@"Yes!" :CGRectMake(nextButtonXPos, nextButtonYPos, nextButtonWidth, nextButtonHeight)]; 
    [next addTarget:self action:@selector(finishStepOne) forControlEvents:UIControlEventTouchUpInside]; 
    [self.stepOneView addSubview:next]; 
} 

-(void) finishStepOne 
{ 
    //Do whatever... 
    NSLog(@"TRY FINISH STEP ONE"); 
    currViewNum = stepTwoViewNum; 
    [self gotoView]; 
} 

-(void) showStepTwo { 

    //Intro text 
    int introTVWidth = self.view.frame.size.width - (2*padSides); 
    int introTVHeight = 1; 
    int introTVXPos = [GeneralHelper GetCenteredXPosForObj:introTVWidth :self.view]; 
    int introTVYPox = 115; 
    NSLog(@"showing step two"); 
    UITextView* introTextView = [[UITextView alloc] initWithFrame:CGRectMake(introTVXPos, introTVYPox, introTVWidth, introTVHeight)]; 
    introTextView.backgroundColor = [UIColor clearColor]; 
    introTextView.font = [UIFont systemFontOfSize:15]; 
    introTextView.textAlignment = UITextAlignmentCenter; 
    NSString* tx = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"alertsIntroStep2" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil]; 
    introTextView.text = tx; 
    introTextView.editable = false; 
    introTextView.scrollEnabled = false; 
    [self.stepTwoView addSubview:introTextView]; 
    [GeneralHelper resizeTextView:introTextView]; 
} 

-(void) gotoView 
{ 
    printf("SHOWING %u", currViewNum); 

    if(currViewNum == summaryViewNum) { 
     [self showSummary]; 
    } 
    if(currViewNum == stepOneViewNum) { 
     [self.view bringSubviewToFront:stepOneView]; 
     [self showStepOne]; 
    } 
    if(currViewNum == stepTwoViewNum) { 
     //[self.view bringSubviewToFront:stepTwoView]; 
     [self showStepTwo]; 
    } 
} 

-(void) setCurrentView 
{ 
    bool isActive = false; //TODO, (temp) this represents if alerts are active or not 
    if(isActive) { 
     currViewNum = 99; 
    } else { 
     currViewNum = 1; 
    } 
} 

답변

1

U는 intially 당신의 initView 방법에 stepOneViewstepTwoView'suserInteractionEnabled = NO을 만들었습니다.

그래서 button 것이 notrecievetouch 어떤 방식으로 stepOneView 내부. 그래서 그것 not receivingclickevents

+0

나는 그것을 넣기 전에 작동하지 않았다. – Baconbeastnz

관련 문제