i try to load a view via UIPopover but my app crash after tap the popover button , i tried to solve it but i don't understand ! here is my code :
-
(IBAction)calendarPopUp:(id)sender {
PopViewController *cal = [[PopViewController alloc]init];
//The compiler tells me the problem comes from this line :
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:cal];
[popOver setDelegate:self];
[popOver presentPopoverFromRect:CGRectMake(113, 64, 226, 129) inView:self permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[popOver setPopoverContentSize:CGSizeMake(226, 129)];
}
I guess you should change inView:self to inView:self.view.
Related
I have a problem since last half-an-hour.I am using UIButton and I want to show UIPopovercontroller on it.But It crashes on it's touchUpinside action.I know this can we easily done if i use UIBarButton but I have some UI specification that's why I can't use UIBarButton and UIToolbar.
So please if someone have any idea about showing UIPopovercontroller on UIButton then please help me.Help would be appriciated.
[popoverController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
You can try using the below Code :
-(IBAction)Show_Menu_Controller:(id)sender
{
if (_colorPicker == nil) {
self.colorPicker = [[[ColorPickerController alloc] initWithStyle:UITableViewStylePlain] autorelease];
_colorPicker.delegate = self;
self.colorPickerPopover = [[[UIPopoverController alloc] initWithContentViewController:_colorPicker] autorelease];
}
[self.colorPickerPopover setPopoverContentSize:CGSizeMake(600.0f, 250.0f)];
[self.colorPickerPopover presentPopoverFromRect:CGRectMake(365,-118 , 300, 200) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; **//Set the Origin & Direction of PopOverController accordingly**
}
I have an error which is causing my app to crash under iOS5 only on the iPad.
The below code is called when the user taps on an item in a uibarbutton item :
- (void)optionSelected:(NSString *)option {
[self.optionPickerPopover dismissPopoverAnimated:YES];
if ([option compare:#"Map View"] == NSOrderedSame) {
NSLog(#"Map View");
MapView * map = [[MapView alloc] initWithNibName:#"MapView" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:map];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStyleDone target:self action:#selector(removeCurrent)];
map.navigationItem.rightBarButtonItem = rightButton;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[map release];
[rightButton release];
[split presentModalViewController:map animated:YES];
}
Can anyone suggest why this occurring in iOS5 ?
You are getting this error because you are attempting to display the 'map' view controller twice. The first time is as the root view controller of 'navigationController' and the second time is via [split presentModalViewController:map animated:YES].
iOS 5 is being a bit more picky than iOS 4 when you try to do strange things with view controllers. Trying to show the same controller twice is a design problem - you need to work out what you are really trying to do and fix it.
(Also, calling a map view controller 'MapView' rather than 'MapViewController' is really confusing)
This error will also occur if you don't follow these guidelines: Creating Custom Content View Controllers
Basically, you need to call:
[yourVC removeFromParentViewController];
if you've
[parentVC addChildViewController:yourVC];
This error may often be paired with something about "UIViewControllerHierarchyInconsistency"
I am trying to display tableviewcontroller in a popover from a barbuttonitem like this :
- (IBAction)sortData:(id)sender {
if(!sortViewController)
sortViewController = [[SortDataViewController alloc] init];
[sortViewController.tableView setDelegate:self];
[sortViewController.tableView setTag:12];
[sortViewController setIsMatter:YES];
sortViewController.contentSizeForViewInPopover = CGSizeMake(150, 100);
sortViewController._radioSelection = 0;
[sortViewController.tableView reloadData];
}
if(!popOverController) {
popOverController = [[UIPopoverController alloc] initWithContentViewController:sortViewController];
}
[popOverController setPopoverContentSize:CGSizeMake(100, 100)];
[popOverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
for the first time it got displayed for 1sec and automatically dismissed and from next time onwards it is not displaying at all. Can anyone please help me in this regard.
Set delegate for the UIPopOVerController...
popOverController.delegate = self;
I am reloading the view after each second to test some requirement and forgot to disable it. So my view is reloading continuously and it's not giving enough time for popover to display it's view. Now I disabled it and the popover is working without any issues.
I have a SplitviewController with multiple possible Detailviews (Webviews, Tableviews, regular UIViews).
As an example, I have a NavigationController on top, then navigate through some tables.
Finally I show some Content, lets say a UIWebview. I rotate the iPad to portrait, and in the toolbar I add a Button from which the popOverController is displayed.
On Buttonclick I say:
if (!popoverController) {
if (self.view.window != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController: [appDelegateiPad naviPad]];
popoverController.delegate = self;
}
}
Here, I instantiate a PopOverController and the Content is the left part of the splitview, from the point I left off. All is nice.
But when I rotate, I get this warning:
CoreAnimation: ignoring exception: Popovers cannot be presented from a view which does not have a window.
And on the screen the popOverController reappears with empty content (black translucent I would say) but I don't know why, since I dismissed it and there cant be another instance since I only create one on buttonclick.
This has been driving me crazy for days.
ANY(!) help is appreciated!
-(void) showPopOver:(id) sender {
NSLog(#"showing popover?");
if (!popoverController) {
if (self.view.window != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:[appDelegateiPad naviPad]];
//RootViewController *r = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle: nil];
// popoverController = [[UIPopoverController alloc] initWithContentViewController:r];
//popoverController.popoverContentSize = CGSizeMake(320, 800);
//popoverController.delegate = self;
}
}
if (![popoverController isPopoverVisible]) {
[popoverController presentPopoverFromBarButtonItem:barButton3 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
//[popoverController presentPopoverFromRect:CGRectMake(10, 10, 20, 20) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
else {
[popoverController dismissPopoverAnimated:NO];
}
}
I think the issue here is that I'm trying to call a mediaPicker and that doesn't support other orientations...
Does anyone have a fix for this?
Here is my current code:
- (IBAction)openMediaPicker:(id)sender {
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES; // this is the default
mediaPicker.modalPresentationStyle = UIModalPresentationPageSheet;
//mediaPicker.prompt = #"Select items to play";
[self presentModalViewController:mediaPicker animated:YES];
[mediaPicker release];
// Init a Navigation Controller, using the MediaPicker as its root view controller
UINavigationController *theNavController = [[UINavigationController alloc] initWithRootViewController:mediaPicker];
[theNavController setNavigationBarHidden:YES];
// Init the Popover Controller, using the navigation controller as its root view controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:theNavController];
// Make a rect at the size and location of the button I use to invoke the popover
CGRect popOverRect = chooseMusicButton.frame;
// Specify the size of the popover
CGSize MySize = CGSizeMake(520.0, 720.0);
[popoverController setPopoverContentSize:MySize animated:YES];
// Display the popover
[popoverController presentPopoverFromRect:popOverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
}
This code is overly complicated. First you present the media picker modally, then you present it as a popover; why? In the popover, you stuff it into a navigation controller before presenting it; why? Presenting a media picker on iPad is much simpler than that:
MPMediaPickerController* picker =
[[[MPMediaPickerController alloc] init] autorelease];
picker.delegate = self;
UIPopoverController* pop =
[[UIPopoverController alloc] initWithContentViewController:picker];
self.currentPop = pop;
[pop presentPopoverFromRect:[sender bounds] inView:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[pop release];
That works in any orientation and even survives rotation while the popover is showing.
All pre-defined modal controllers support all orientations but they must be presented from the root view controller for them to behave correctly in orientation and rotation. My guess is that that the "self" in your code is not the root view controller. You may have to re-architect the code a bit to make this happen if possible.
There are other hacks I have seen to make it work without being presented from the root view controller but they all seemed to be asking for trouble such as extending UIViewController with a category to over-ride interfaceOrientation.
If you can present it from the root view controller, it would be the simplest and cleanest but I realize it is not always possible (e.g., it is inside a library you are providing to third party apps to embed).