-2

如何创建特殊的 popOver?我手动创建了一个具有所需设计的新类。

在此处输入图像描述

然后我想像 PopOver 一样加载它

在此处输入图像描述

-(void) buttonAction {
UIViewController* popoverContent = [[UIViewController alloc] init];

myThirdPop * showHere;//Created class which I load as Popover
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"myThirdPop" owner:self options:nil];
showHere = [nib objectAtIndex:0];
popoverContent.view = showHere.myView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 350);
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:myButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

但是当我尝试点击按钮时,我的应用程序崩溃并显示 exc_bad_access 怎么了?

4

3 回答 3

2
Use this code to create the popover

 -(IBAction)Click_event
{      UIPopoverController *popoverview;
if(![popoverview isPopoverVisible])
     {
  Popview *pop = [[Popview alloc] initWithNibName:@"Popview" bundle:nil];
  popoverview = [[UIPopoverController alloc] initWithContentViewController:pop];
  [popoverview setPopoverContentSize:CGSizeMake(600.0f, 500.0f)];
   [popoverview presentPopoverFromRect:CGRectMake(400, 400, 0, 0)   inView:self.Click_but  permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
 }
else
 {
  [popoverview dismissPopoverAnimated:YES];
 }
  }

  Lets try this. It may be helpful for you  
于 2012-08-30T12:42:15.697 回答
2

试试这种方式,你可能会解决问题....

PopimagepickerViewController.h

            UIPopoverController *popoverController;


          UIPopoverController *popoverimagview;  // imagepicker popoverview

PopimagepickerViewController.m

 -(IBAction)popbtn_Click:(id)sender

{

UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,230,180)];
popoverView.backgroundColor = [UIColor whiteColor];

popoverContent.view=popoverView; popoverContent.contentSizeForViewInPopover = CGSizeMake(230, 180); // 设置popoverview的宽高

//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
CGRect popoverRect = [self.view convertRect:[popbtn frame]
                                   fromView:[popbtn superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x  = popoverRect.origin.x;
[popoverController
 presentPopoverFromRect:popoverRect
 inView:self.view
 permittedArrowDirections:UIPopoverArrowDirectionUp + 
 UIPopoverArrowDirectionLeft           //pooverview down direction
 animated:YES]; 


[popoverView release];
[popoverContent release];

}

于 2012-08-30T13:13:00.020 回答
0

您的代码似乎过于复杂且不标准。我使用此代码创建一个弹出框。

(我已经编辑了这个以匹配你的情况,但它没有经过测试)

-(void) buttonAction:(id) sender
{
    UIViewController *myThirdPop = [[NSBundle mainBundle] loadNibNamed:@"myThirdPop" owner:self options:nil];

    UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:myThirdPop];

   [popoverController presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

   [myThirdPop release];
}
于 2012-08-30T12:45:01.453 回答