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**
}
Related
I have created a popover and it is showing me my in app purchase items list. I have implemente classes used by Ray Wenderlich tutorials. But something is definitely wrong. My problems are:
Popover is being shown with Max height. (I don't want it to be shown with MAX height of iPad)
If i close popover by clicking some where else, and again click the button to show popover, It opens popover but doesn't load the view in it.
Please help guys I'm in real confusion/problem.
I am displaying popOverViewController from SearchDelivery.xib that contains tableView & Search bar in it. In other .xib file I am showing popover on button click code is below that can help you .
-(IBAction)deliveryList:(UIButton*)sender
{
SearchDelivery *searchDel1=[[SearchDelivery alloc]initWithNibName:#"SearchDelivery" bundle:nil];
[searchDel1 loadDelAdd:self.arr];
self.searchDel=searchDel1;
[searchDel1 release];
UIPopoverController *popover=[[UIPopoverController alloc]initWithContentViewController:searchDel];
popover.delegate=self;
CGRect rect=searchDel.view.frame;
popover.popoverContentSize=rect.size;
self.popOverController=popover;
[popover release];
[popOverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:0 animated:YES];
}
popoverContentSize Property is used to set width and height of popOverView.
Try the below given code
-(IBAction)setData1:(id)sender
{
UIViewController *popoverContent=[[UIViewController alloc] init];
UITableView *tableView1=[[UITableView alloc] initWithFrame:CGRectMake(265, 680, 0, 0) style:UITableViewStylePlain];
UIView *popoverView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 300)];
popoverView.backgroundColor=[UIColor whiteColor];
popoverContent.view=popoverView;
popoverContent.contentSizeForViewInPopover=CGSizeMake(200, 420);
popoverContent.view=tableView1; //Use this if you like to add a tableView in popover
tableView1.delegate=self;
tableView1.dataSource=self;
self.popoverController=[[UIPopoverController alloc] initWithContentViewController:popoverContent];
[self.popoverController presentPopoverFromRect:CGRectMake(400, 675, 1000, 1000) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
I am extremely new to iPhone development, so please forgive this post if it seems naive. I am trying to simply add a subview to my current view (if this is the best way to open a new screen on iPhone). Here is my code:
QuickCalcController *aViewController = [[QuickCalcController alloc]
initWithNibName:#"QuickCalcController" bundle:nil];
aViewController.view.frame = CGRectMake(0, 100, quickCalcController.view.frame.size.width, quickCalcController.view.frame.size.height);
[self.view addSubview: quickCalcController.view];
self.view.bounds = quickCalcController.view.bounds;
The problem is, when this code gets called, the view shown is not QuickCalcController.xib. It is MainView.xib. The file's owner is QuickCalcController... am I missing something?
Thanks in advance.
You should just ask the mainViewController to present the QuickCalcController:
QuickCalcController *aViewController = [[QuickCalcController alloc]
initWithNibName:#"QuickCalcController" bundle:nil];
[self presentModalViewController:aViewController animated:YES];
[aViewController release], aViewController = nil;
Then to dimiss QuickCalcController just call [self dismissModalViewControllerAnimated:YES]; in QuickCalcController.
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.
Could anyone please tell me what the rect and view should be? I do not understand what I shall pass to the selector. An example would be great!
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverController_class/Reference/Reference.html
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
I use this pretty often. Let's say you want to tap on an image and present a popover with information about it. Assuming you have a gesture recognizer with the selector method (handleImageTap:) on your image, here would be an example code to make that happen:
- (void)handleImageTap:(UIGestureRecognizer *)gesture {
// initialize your popover view controller and assign it to your popoverController
MyPopoverViewController *content = [[MyPopoverViewController alloc] init];
popoverController = [[UIPopoverController alloc] initWithContentViewController:content];
popoverController.popoverContentSize = CGSizeMake(600, 600);
popoverController.delegate = self;
[content release];
if (popoverController.popoverVisible == NO) {
// you can find the tappedImage through the gesture by searching up superviews if you don't already have a reference to it;
[popoverController presentPopoverFromRect:[tappedImage frame] inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
[popoverController dismissPopoverAnimated:YES];
}
}
So basically, view will be self.view becuase you are displaying it from the current view controller. The rect is just whatever rect you want the popover to display from. In this case, it is set up to be displayed from the frame of an image. I hope this helps you. If something is still confusing, I'll be happy to try and clear it up
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.