0

UIPopoverController にボタンを追加しましたが、タッチに反応しないようです。UIPopoverController に何らかのプロパティを設定する必要があるのか​​ 、それとも何なのかわかりません。ポップオーバー ビューとボタンをレンダリングするコードを次に示します。

- (void)topicImageButtonPressed
{
    CGRect aFrame = CGRectMake(0.0, 0.0, 1000.0, 600.0);
    UIViewController *aView = [[UIViewController alloc] init];
    aView.view.frame = aFrame;
    UIImageView *iView = [[UIImageView alloc] init];
    [iView setContentMode:UIViewContentModeScaleAspectFit];
    [iView setImage:self.topicImageView1.image];
    aView.view = iView;

    UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [nextButton addTarget:self 
                   action:@selector(quizButtonPressed:)
     forControlEvents:UIControlEventTouchUpInside];
    [nextButton setTitle:@"Next" forState:UIControlStateNormal];

    nextButton.frame = CGRectMake(700.0, 550.0, 160.0, 40.0);

    [aView.view addSubview:nextButton];

    //aView.view.backgroundColor = [UIColor colorWithPatternImage:self.topicImageView1.image];

    imagePopoverController = [[UIPopoverController alloc] 
                         initWithContentViewController:aView];
    imagePopoverController.popoverContentSize = CGSizeMake(1000, 600);

    imagePopoverController.passthroughViews = [NSArray arrayWithObject:nextButton];

    [imagePopoverController presentPopoverFromRect:CGRectMake(212, 10, 1000, 600) inView:self.view 
                     permittedArrowDirections:0 animated:YES];
}
4

2 に答える 2

1

これを追加すると機能しました。iView.userInteractionEnabled = YES;

于 2012-04-21T02:51:00.810 に答える
0
UIViewController *popoverContent = [[UIViewController alloc]init];
    UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];

    datepiker= [[UIDatePicker alloc]init];
    [datepiker setFrame:CGRectMake(0, 0, 320, 216)];
    datepiker.datePickerMode=UIDatePickerModeDateAndTime;
    datepiker.hidden=NO;
    datepiker.minimumDate=[NSDate date];

    [self.view addSubview:datepiker];

    [datepiker release];
    // [datepiker addTarget:self action:@selector(changedDate:) forControlEvents:UIControlEventValueChanged];

    btn_add=[[UIButton alloc]initWithFrame:CGRectMake(115, 250, 100, 30)];
    [btn_add setTitle:@"Add" forState:UIControlStateNormal];
    [btn_add setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
    [btn_add setBackgroundColor:[UIColor redColor]];
    [btn_add addTarget:self action:@selector(AddDate:) forControlEvents:UIControlEventTouchUpInside];
    [popoverView addSubview:btn_add];

    btn_cancel=[[UIButton alloc]initWithFrame:CGRectMake(115, 300, 100, 30)];
    [btn_cancel setTitle:@"Cancel" forState:UIControlStateNormal];
    [btn_cancel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
    [btn_cancel setBackgroundColor:[UIColor redColor]];
    [btn_cancel addTarget:self action:@selector(CancelDate:) forControlEvents:UIControlEventTouchUpInside];
    [popoverView addSubview:btn_cancel];

    [popoverView addSubview:datepiker];
    [popoverView addSubview:btn_add];
    popoverContent.view = popoverView;
    popoverContent.contentSizeForViewInPopover = CGSizeMake(320,350);


    self.popoverController = [[UIPopoverController alloc]
                                  initWithContentViewController:popoverContent];
    [self.popoverController  presentPopoverFromRect:CGRectMake(230,250, 320,220) 
                                                 inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];


    [popoverView release];
    [popoverContent release];


-(void)AddDate:(id)sender
{
}
-(void)CancelDate:(id)sender
{
[popoverController dismissPopoverAnimated:YES];

}

これを試してください..私にとってはうまくいきます。

于 2012-04-20T13:11:21.847 に答える