iOS- How to add objects in a popoverController in iPhone? - ios

In my app, I have a button, when it is clicked a popoverView will be displayed.
I used the following code
First, I added UIPopover+Iphone.h and UIPopover+Iphone.m files from the link Popover view for iPhone using XCode 5
-(IBAction)buttonClicked:(id)sender
{
UIViewController *popoverViewController=[[UIViewController alloc]init];
UIPopoverController * popoverController=[[UIPopoverController alloc]initWithContentViewController:popoverViewController];
popoverController.popoverContentSize=CGSizeMake(200, 200);
[popoverController presentPopoverFromRect:timingTextField.frame inView:self.view permittedArrowDirections: UIPopoverArrowDirectionUp animated:YES];
}
I got an output like this
Now I want to insert some objects in it, say a button or some other equivalent UI element. Can anyone please suggest me something. Thanks in advance.

Add the elements you want to your UIViewController *popoverViewController. this is the viewcontroller that is displayed in PopoverController * popoverController.

Related

xcode 7.3.1 my storyboard segues to popover are mis-aligned. Objective c

If I simply drag a popover segue from a button, the arrow aligns to the top left of the button, instead of the center.
Anyone have any ideas?
I solve this problems using PopoverController, use UIPopoverControllerDelegate
myPopover = [[UIPopoverController alloc] initWithContentViewController:destinationViewController];
myPopover.delegate = self;
[myPopover presentPopoverFromRect:((UIView *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

How to load multiple views without using storyboard in xcode 6.2

I created an iOS 8 project in XCode 6.2, I removed the storyboard, modified the appDelegate and the plist file. I added a new view (named "primary", with the xib, h, and m files) with a button and called it from the modified appdelegate. It works so far. I created a second view (named "second") and want to call it from "primary" once the button is called.
I tried adding the code below from Primary's button click event:
second *secondView = [[second alloc] initWithNibName:nil bundle:nil];
[self presentViewController:secondView animated:NO completion:nil];
*Result: Attempt to present on whose view is not in the window hierarchy!
Would be nice if anybody can help me or point me on how to load a view from another view programatically without using Storyboards?
Thanks in advance.
Best Regards,
VinceV
Do you have a UINavigationController? please show us some more of your project since im not able to solve this question with the current info provided
Edit
Make sure you call the presentViewController code from your second
ViewController
//Button Event in SecondViewController.m
(void)handleClick:(id)sender
{
SecondViewController * controller = [SecondViewController] alloc] init];
[self presentViewController:controller animated:true completion:nil];
}

UIReferenceLibraryViewController in UIPopovercontroller

I was recommended to use a UIPopovercontroller in order to display my UIReferenceLIbraryViewController so that the dictionary does not take up the entire screen when I click my UIButton "search"
What I have is a UITextField that takes in the string/word, a button that will search it and pull up the UIReferenceLibraryViewController.
I'm having problems using a popovercontroller to do this. When I tried it, the button doesn't respond. Any tips/help??
edit:
UIReferenceLibraryViewController in a popover
It was originally
if([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:searchTerm])
{
UIReferenceLibraryViewController *referenceLibraryVC = [[UIReferenceLibraryViewController alloc] initWithTerm:searchTerm];
[self presentModalViewController:referenceLibraryVC animated:YES];
}
which makes it take up the entire ipad screen
Does UIReferenceLIbraryViewController have initWithFrame? that solution didn't seem to work for me either
Thanks to Leo Nathan's help, it works now.
self.masterPopOverController = [[UIPopoverController alloc] initWithContentViewController:referenceLibraryVC];
[self.masterPopOverController presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I didn't connect it correctly in the XIB file and it wasn't implemented in the correct place in the IBAction for ButtonPress

Show annotation while map view opens

Is ti possible to show an annotation while a map view is opening? I have looked at other pieces of code, but they all involve objectAtIndex, and I am not using a tableview for this selection.
Here is the code I am using to select the view, which is supposed to open when I click a button:
Screen1ViewController
- (IBAction)mapPressed1:(UIButton*)sender
{
mapnew *controller1 = [[[mapnew alloc] initWithNibName:#"mapnew" bundle:nil] autorelease];
controller1.delegate = self;
controller1.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller1 animated:YES completion:nil];
// IS IT POSSIBLE TO DO SOMETHING LIKE THIS INTO THE IBACTION FOR IT TO WORK:
[self.mapView selectAnnotation:NameOfAnnotationForSpecificLocationCoordinates animated:YES];
}
The map that is supposed to open at the click of a button should be able to recognize where the click came from, and open the right annotation. Each point on the map has a name assigned to it.
Any help is appreciated.
Thanks
Asked and answered here: How to open call out MKAnnotationView programmatically? (iPhone, MapKit)
All you need to do is make pass the data to your controller1 so it is ready to show it the moment it appears.

UIPickerView issue in iPad

I am repeating this question again because i couldn't find any solution.
My problem i have an XIB where i have labels and a UIPickerView.I am trying to use this XIB inside a UIPopOverController in iPad.But the view is not rendered properly.Actually this is the view which i am adding it to the popover window.
This is the code which i am using
MyPricePickerViewController *priceviewobj=[[MyPricePickerViewController alloc]init];
UINavigationController *navigationcontroller=[[UINavigationController
alloc]initWithRootViewController:priceviewobj];
popover = [[UIPopoverController
alloc]initWithContentViewController:navigationcontroller];
[popover setPopoverContentSize:CGSizeMake(290,410) animated:YES];
[self.popover presentPopoverFromRect:CGRectMake(10,212,20,30) inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
I display other XIBs which dont have a UIPicker view and they are displayed properly.When i run the application the popover is rendered as follows
Please anybody suggest me a possible solution to this problem.Thanks in advance

Resources