0

2 つのサブビューをセットアップした ViewController があります。それらを切り替えたい。しかし、StepOne ビュー内のボタンがトリガーされません。

ビューを正しい方法で使用していますか? このボタンでクリック イベントを受信するにはどうすればよいですか?

ありがとう

@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;
    }
}
4

1 に答える 1

1

U はstepOneViewstepTwoView's userInteractionEnabled = NO最初initViewはあなたの方法で作成しました。

だからbutton内部はどうにかstepOneViewなるでしょうnot recieve touch。それはそうnot receiving click events

于 2012-08-27T06:06:43.897 に答える