How do I add a button to the subtitle of an MkMapView custom annotation? - iphone-sdk-3.0

Basically my program displays many annotations on a map. after the user clicks on one, It displays the title of the location. How can I add a button under the title that will display a new window with more information on the location? I would also be content with a button at the bottom of the screen that is greyed out until one location is selected.

In the viewForAnnotation method, set a button as the callout accessory view:
annotationView.canShowCallout = YES;
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView = button;
You can use rightCalloutAccessoryView or leftCalloutAccessoryView but the documentation recommends putting a disclosure button on the right.
Respond to the button press in the calloutAccessoryControlTapped method.

Related

NSEvent from a NSButton

I have a NSTableView and each row contains a button. I also have a menu associated with the table.
The issue is : I want to show the menu on click of button. If possible do not show on right click.
The action method is :
- (IBAction)showMenu:(NSButton *)button {
NSLog(#"show menu");
NSMenu *menu = [self.tableView menu];
NSEvent *event = [[NSEvent alloc] init];
[NSMenu popUpContextMenu:menu
withEvent:event
forView:button];
}
Here what to do with event? If I use nil then the menu is showed at bottom left corner, not next to the button.
Any guidance would be appreciated.
You could try using -[NSMenu popUpMenuPositioningItem:atLocation:inView:]. This method doesn't take an NSEvent argument. Instead, you give it a view and a location in the view's coordinate system, and the menu positions itself (or one of its items) over that location.
But I would suggest you don't use an NSButton at all. If you use an NSPopUpButton instead, it will take care of showing the menu at the correct location on a left-click.

change a backgroundcolor of button inside a view that has a UITapGestureRecognizer and buttons

I have a view with a UITapGestureRecognizer(numberoftapsrequired = 1),and this view also has some buttons.
I want to change background-color of a button which is tapped, select only one to change.
I don’t know how to get this button to change its background-color. Like this figureexample
Get rid of the gesture
Create a IBOutletCollection called buttons with your buttons in it
Add the following code to your VC.
- (IBAction) didTapButton:(UIButton*) sender {
sender.backgroundColor = [UIColor redColor]; // or whatever
// create a IBOutletCollection called buttons with your buttons in it
for (UIButton *b in self.buttons) {
if (b != sender) {
b.backgroundColor = [UIColor blueColor]; // or whatever
}
}
}
Set this action to the "touch up inside" for each button.
If I got your question correctly, you are adding the tap gesture in order to recognize the click event. No need to give tap gesture in the entire view. Give actions for each of the buttons and change their background colors in the action method

How to put a tableView's Edit button in the toolbar when a search bar is shown (as in Apple's mail app)?

I would like to put the Edit button in the toolbar at the bottom. The Edit button is usually instantiated with self.navigationItem.rightBarButtonItem = self.editButtonItem in viewDidLoad and normally placed in the navigation bar.
When trying to put the Edit button (= self.editButtonItem) in the toolbar (by adding it to the toolbar items), the buttom does not appear. However, all other toolbar items, which I have added using Interface Builder are presented correctly.
How would you recommend adding this button to the toolbar?
The reason for adding the Edit button to the toolbar is to be enable the table's edit mode when a UISearchBar enabled search is currently active and the searchbar hides the edit button in the navigation bar.
I would like to get the same behavior as in Apple's email app, where the Edit button is shown in the toolbar when search is active.
I would appreciate any suggestions.
Thank you for your help!!
You can add a Edit button to the toolbar this way:
self.editButton =
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:nil
action:nil]
autorelease];
NSArray *toolbarItems =
[NSArray arrayWithObjects:self.editButton,nil];
self.toolbar.items = toolbarItems;
If you want to hide/show it, just toggle its hidden property:
self.editButton.hidden = YES;
You could do it manually, by creating a new UIBarButtonItem with style UIBarButtonSystemItemEdit. Then simply add it to the tabbar, assign a target and action and call [tableView setEditing:YES animated:YES];.

Is it possible to display two views at the same time without switching option in view based application?

I am new to iOS programming and Xcode. I am doing a painter application via View based application in Xcode. Here I am going to draw in mainview and customize the settings in new view by click a button which is in mainview.
Whenver I click the button in mainview, it want to display a customize view in the mainview. mainview shouldnot be hidden. Customize view, it just a small view which display in mainview itself.
How can I do this?
Use like -
// Action on click of button -
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(xpos, yPos, width, height]; //pass these values whatever you want
[mainView addSubView:newView];
// Now when you want to remove this -
[mainView removeFromSuperView:newView];

How do I add a navigation bar's Done button to a popover's passthroughViews?

I'm working in an iPad app that has a split view with a navigation controller in the detail view. The deepest view that can be in the navigation stack is an edit view where the user can edit data. I put an edit button as the rightBarButtonItem and when editing starts, change it to a done button.
When editing commences and the user touches on a particular field, I present a popoverview with a list of possible choices filtered by what they are typing - a form of autofill based on all the values of that field in all other objects.
This works fine, except if you try touching on the done button. The popover eats this touch and dismisses itself. So the user has to touch done again.
I tried using the uipopovercontroller's passthroughViews property, but UIBarButtonItem is not a view and there is no documented way to get the view for the done button or even the navigation bar. I can access the variable in gdb, but it isn't accessible via KVC.
Any ideas on how I can prevent the need to tap done twice?
I've thought about a gesture recognizer on the window, but that seems messy and I'd have to handle rotation.
In case anyone gets here from google, copypaste from other question:
The only solution I found for now is to create UIBarButtonItem with custom UIButton using
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//code for styling button
UIBarButtonItem *b = [[[UIBarButtonItem alloc]
initWithCustomView:button]
autorelease]
and then
popoverController.passthroughViews = [NSArray arrayWithObject:b.customView];
But be prepared - you cannot create UIButton that looks like UIBarButtoItem. I ended up with creating image that reassembled UIBarButtonItem.