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.
Related
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
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.
I am trying to change where a button leads to depending on the selected row of a picker view. I am trying to display data depending on a certain year and I can make the picker display the available years and change a label to the corresponding year, but how can i make the "go" button I;ve created lead to the correct view controller?
Maybe you haven't had time to figure this out, maybe you have, but this is what I would do. You have a text field that you will populate with a picker, call this the "yearTextField." Then you have a button that you want to change the action depending on the year in question. Call this "myChangableButton." This is just for an example, you can call them anything you like. I put my initial view controller in a navigation view controller to have better control of the views. For this example I made two different years 1942, and 1971. They each have their own view controller that I named "FourtyTwoViewController" and "SeventyOneViewController" in my first view controller you will need to import these into the .m file. Like this..
#import "ViewController.h"
#import "FourtyTwoViewController.h"
#import "SeventyOneViewController.h"
Also, make sure when you drag out the new view controllers in the storyboard, that you name them as such. And don't forget to use that name as the Storyboard ID, found under the Identity inspector. Now for myChangableButton I made an action that will bring up whichever view controller you want based on the text in the yearTextField like this..
- (IBAction)myChangableButton:(id)sender
{
if ([_yearTextField.text isEqual: #"1942"])
{
FourtyTwoViewController *ftvc = [self.storyboard instantiateViewControllerWithIdentifier:#"FourtyTwoViewController"];
//[self presentViewController:ftvc animated:YES completion:nil];
[self.navigationController pushViewController:ftvc animated:YES];
}
else if ([_yearTextField.text isEqual: #"1971"])
{
SeventyOneViewController *sovc = [self.storyboard instantiateViewControllerWithIdentifier:#"SeventyOneViewController"];
//[self presentViewController:sovc animated:YES completion:nil];
[self.navigationController pushViewController:sovc animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Watch Out!" message:#"Put in valid date" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
The line of code that I commented out will bring up a modal transition, but I prefer a push since that gives you a great back button. That's it. I hope this helps you on your project. Make a comment if you have any questions, and good luck. And WELCOME! to SO!!
EDIT #1
Here is a sample of how I set the initialUrl in a viewcontroller that I pushed.
VideoViewController *vvc = [self.storyboard instantiateViewControllerWithIdentifier:#"VideoViewController"];
vvc.initialUrlString = urlString;
vvc.descriptionString = descriptionString1;
[self.navigationController pushViewController:vvc animated:YES];
I imported VideoViewController into the first view controller. And VideoViewController has two properties called initialUrlString and descriptionString. In the first view controller I have two properties called urlString and descriptionString1, these are set in the first view controller during another method and then passed into the second.
So in my universal app I have a section where a person can look at an existing list of notes from our system (retrieved through a simple web service) and then also create a new note if they want. So for the iphone it's pretty simple layout, a TableViewController for displaying the list with a "Add" button on the NavigationBar that presents the modalview for adding the new item. On the iPad though, the same layout has a lot of wasted space so I opted to go with the popOver method to show the list in a popOver and then let them add from there. My problem is that when the user clicks on the Add button within the PopOver view, the modal view comes up full screen instead of just coming up within the popover view. Here's the code I have so far:
-(void) AddButtonPressed:(id)sender {
NewNoteVC *newNote = [[[NewNoteVC alloc] initWithNibName:#"NewNoteVC" bundle:nil] autorelease];
newNote.defaultClientID = defaultClientID;
UINavigationController *navCon = [[[UINavigationController alloc] initWithRootViewController:newNote] autorelease];
if ([isPopOver isEqualToString:#"YES"]) {
[navCon setModalInPopover:YES];
[self.navigationController setModalInPopover:YES];
[self.navigationController presentModalViewController:navCon animated:YES];
}
else {
[self.navigationController presentModalViewController:navCon animated:YES];
}
}
The "isPopOver" string is just a placeholder sent from the previous screen that called this TableView (I know I can switch this to a boolean for better performance I just put this together real quick to try it out). I know I messed up somewhere, I just don't know what setting I need to get this working correctly.
You need to define the view controller's modalPresentationStyle to be "current context".
navCon.modalPresentationStyle = UIModalPresentationCurrentContext;
This will result in modal view controller filling the popover like the popover's root controller.
Try using the presentViewController:animated:completion: instead of presentModalViewController:animated: and set self.navigationController.definesPresentationContext = YES
My ipad project is master-detail view based. There is a button on detail view's toolbar, when user tap on the button, it popup a popover view to show four buttons (as menu). Three of buttons' actions are like the following (the three buttons show three different model form sheets):
- (void) showOnlineSgf
{
NSLog(#"showOnlineSgf");
TGOOnlineSgfViewController *dlg =
[[TGOOnlineSgfViewController alloc] initWithNibName:#"TGOOnlineSgfViewController"
bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:dlg];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:nav animated:YES completion:nil];
dlg = nil;
nav = nil;
}
The other button's action is to show a MFMailComposeViewController. Code is like the following:
- (void) emailCurrentGame
{
NSLog(#"email current game");
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
picker = nil;
}
The weird behavior is that when I tap the button what should execute showOnlineSgf(), but emailCurrentGame() is actually executed. When I set a breakpoint in showOnlineSgf(), it's hit, and step by step, each statement in showOnlineSgf() is executed. But the result on screen is a MFMainComposeViewController shows up.
I know this question is hard to answer. Any idea is appreciated.
Check your outlet connection of your UIButton that triggers showOnlineSgf. Most likely you copy pasted your UIButton in Interface Builder, which causes it to copy its assigned action as well. Then you've connected your other action, resulting in your UIButton having two actions.
To resolve the problem, simply disconnect your UIButton that triggers showOnlineSgf from the emailCurrentGame action.
Sounds like you copy pasted in the interface builder an already connected button. Check if the button has more than one action assigned.