-2

How can I create special popOver? I have manually created a new class, with needed design.

enter image description here

Then I want to load it like a PopOver

enter image description here

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

}

But when I trying to tap the button, my app crashes with exc_bad_access What`s wrong?

Arthur
  • 1,740
  • 3
  • 16
  • 36
  • Add an exception breakpoint so that you can see what line of your code is causing the crash. See here for how to do it: http://stackoverflow.com/q/4961770/472344 – Darren Aug 30 '12 at 12:07

3 Answers3

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  
Jayaraj
  • 261
  • 1
  • 2
  • 10
  • `[popoverview presentPopoverFromRect:CGRectMake(400, 400, 0, 0) inView:self.Click_but permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];` -- here **click button** mean the button ur touching to show the popover – Jayaraj Aug 30 '12 at 12:51
2

Try this way u may fix the issue....

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); // Set the popoverview Width and height

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

}

iCrazyDev
  • 925
  • 5
  • 16
0

Your code seems overly complex, and non standard. I use this code to create a popover.

(I've edited this to match your case, but it's not tested)

-(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];
}
Snips
  • 6,575
  • 7
  • 40
  • 64