1

我在我的项目中使用 WEPopover。我已经集成了它,它正在显示 PopoverController。我添加为 contentViewController 的类是 UITableViewController 的子类。我在它的 didSelectRowAtIndexPath 上加载另一个视图控制器,但它没有第一次显示这个视图。当我再次点击它时它会出现。我正在添加我的代码。请帮我解决这个问题。

UITouch 上的代码:-

if([[touch view] isKindOfClass:[backGroundImageView class]] && numTaps ==1)

    { 

            CGPoint startLocation   = [touch locationInView:backGroundImageView];

             startX = startLocation.x;
             startY = startLocation.y;

        CGRect rect = CGRectMake(startX, startY, 300, 90); 



        if(self.popoverController)
        {

            [self.popoverController dismissPopoverAnimated:YES];
            self.popoverController = nil;

        }
        else
        {

        UIViewController *contentViewController = [[WEPopoverContentViewController alloc] initWithStyle:UITableViewStylePlain];


        self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];



        if ([self.popoverController respondsToSelector:@selector(setContainerViewProperties:)]) {
            [self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]];
        }

        self.popoverController.delegate = self;

        //Uncomment the line below to allow the table view to handle events while the popover is displayed.
        //Otherwise the popover is dismissed automatically if a user touches anywhere outside of its view.

        self.popoverController.passthroughViews = [NSArray arrayWithObject:backGroundImageView];
        NSLog(@"rect1: %@", NSStringFromCGRect(rect));

        [self.popoverController presentPopoverFromRect:rect  
                                                inView:backGroundImageView 
                              permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown|
                                                        UIPopoverArrowDirectionLeft|UIPopoverArrowDirectionRight)
                                              animated:YES];


}
4

1 回答 1

1

else部分尝试这个小改变,可能会有所帮助因为我已经使用这种方式并且它工作正常。

self.popoverController = [[[WEPopoverContentViewController alloc] initWithContentViewController:yourAnotherViewController] autorelease];

假设 self.popoverController 是 WEPopoverContentViewController 的对象
假设 yourAnotherViewController 已分配

于 2012-08-06T14:37:29.513 回答