English 中文(简体)
UIButton在一家人居住时没有回应插手。
原标题:UIButton does not respond to touchupinside when in a uipopover

我在我的UIPopover增加了一个 but子。 主计长看来没有回答问题。 我不知道我是否应该把一些财产交给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];
}
问题回答

Adding this made it work. iView.userInteractionEnabled = YES;

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];

}

它为我成功工作。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签