I'm new to iOS and working on Google Map SDK and able to show the map on the view but now
I want to add a UITextField and enter the location over there
On buttons click that location should be shown in the map
So please kindly help me out.
I would suggest you to add buttons on the UINavigationBar or by placing a UIToolBar on the top of the map view and then by clicking on it show a UIAlertView with textfield that takes in the input and after the alert's ok is pressed take the location entered and do your stuff. Don't add buttons on the map,it would bring down the usability factor.
If you have a navigation bar already, try this
UIBarButtonItem *locationButton = [[UIBarButtonItem alloc] initWithTitle:#"location" style:UIBarButtonItemStyleBordered target:self action:#selector(showAlertWithTextField)];
self.navigationItem.rightBarButtonItem=locationButton;
-(void)showAlertWithTextField{
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:#"Enter Location" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Add", nil];
[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1)
NSLog(#"%#",[[alertView textFieldAtIndex:0]text]);
}
Related
I have an Iphone application in which when i am pressing a button it shows an alertview to chose the background.whichever background user is chosing will be played as the background of the audio clips.But now i need to add another alert before i am showing this alert for giving some warning.after that only i need to pop the second one.but i was done that chosing alert in the didappear of that viewcontroller and set it as a Uialertview delegate.and on the button actions i was doing different actions.Can anybody help me on achieving this?
proAlertView *loginav1=[[proAlertView alloc] initWithTitle:#"title" message:#"Choose a Background to play with this program?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Field",#"Beach", #"Stars",nil];
[loginav1 setBackgroundColor:[UIColor colorWithRed:0.129 green:0.129 blue:0.129 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.625 saturation:0.0 brightness:0.8 alpha:0.8]];
[loginav1 show];
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
//[self play];
//moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
if(actionSheet.tag==123)
{
[self backButtonPressed];
}
}
else if (buttonIndex == 1)
{
videoFile = [[NSBundle mainBundle] pathForResource:#"video-track" ofType:#"mp4"];
[self play];
moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
}
how can i include another alert before this is my question?
Initialize first Alertview
UIAlertView *al1 = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"Warning Msg!!!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
al1.tag=1;
al1.delegate=self;
[al1 show];
Implement Delegate method
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView.tag==1){
// implement button events for first Alertview
if(buttonIndex==1){
//First button clicked of first Alertview
UIAlertView *al2 = [[UIAlertView alloc] initWithTitle:#"Choose BG" message:#"Choose BG?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"1",#"2",#"3", nil];
al2.tag=2;
al2.delegate=self;
[al2 show];
}
}
if(alertView.tag==2){
// implement button events for second Alertview
if(buttonIndex==1){
// First button clicked second Alertview.
}
}
}
Controller Class header
#interface ViewController : UIViewController<UIAlertViewDelegate>{
}
Hope this will fulfill your need !
You can do like this, first display warning message in alertview and when user click OK in alertview then in alertview delegate method write code to display second alertview where user can choose background.
I am bringing up an UIAlertView that works fine in portrait layout, but when in landscape mode - the message doesn't appear.
It is a standard UIAlertView, with three buttons.
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"one", #"two", nil];
I have tried moving the buttons down (according to the height of the message label) and resizing the alert according to the relocated buttons, but the message still doesn't appear, despite there being plenty of room for display.
Setting the UILabel background to some color for debugging shows that it just isn't displayed..
EDIT:
The UILabel is there - It's just not being displayed.
In the willPresentAlertView method, I can see the UILabel in the NSAlertView's subviews.
It appears to be a bug with the layout code for UIAlertView. After fiddling a bit in the debugger I managed to get this workaround:
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"one", #"two", nil];
[alert show];
// for some reason we have alpha 0 for 3 or 4 buttons
[[[alert subviews] objectAtIndex:2] setAlpha:1];
// also, for 3 buttons the height goes to 10 -> proof of concept 'fix'
[[[alert subviews] objectAtIndex:2] setFrame:CGRectMake(12, 45, 260, 24)];
[alert release];
This is just a proof of concept. A real workaroung should iterate ober the subviews and fix only labels that have either height to small or alpha==0
Probably you missed:
[alert show];
You can directly use uialertview and create object of it. Then pass title and message and button and also other button.....And call click button method.
//Example
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Title" message:#"The message."
delegate:self cancelButtonTitle:#"button 1" otherButtonTitles:#"button", nil];
[alert show];
[alert relaese];
//Then use this method
-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the ok/cancel buttons
if(buttonIndex==0)
{
NSLog(#"Ok");
}
else
{
NSLog(#"cancel");
}
}
I'd like to create a popup menu, from my tab bar.
I've seen them, but I'm not sure what they called ?
Kind of like a speak bubble.
I think copy / paste is the sort of thing I mean.
You are searching for the UIMenuController.
This question might help you.
That could be the UIActionSheet. You might want to give it a try.
//Your delegate for pressed buttons.
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//Your Action for pressed button.
[actionSheet release];
}
//Declare a method to show your sheet
-(void)showActionSheet
{
UIActionSheet *menu = [[UIActionSheet alloc]
initWithTitle: #"Action Sheet Title"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Delete"
otherButtonTitles:#"Other Button1", #"Other Button2", nil];
[menu showInView:self.view];
}
But you said "bubble", so that could also be the UIAlertView.
Try this:
-(void)showAlertView
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert!"
message:#"This is the message that pops up in the bubble."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
On the iPad, you'd want UIPopoverController, but I think that on the iPhone the same sort of interactions are meant to be performed by a separate, full screen controller or by a UIActionSheet. There's no speech bubble on the iPhone such that I'm aware.
I am implementing an action sheet. When I press "ok" button, do these, press "cancel" go back. The "ok" button is working fine, but when I press the "cancel" button, nothing happens, it doesn't retract or do anything, just hang at the actionsheet view.
Below is my code:
To create button on the nav bar:
UIBarButtonItem *clearButton = [[[UIBarButtonItem alloc] initWithTitle:#"Clear History"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(ClearHistoryAction:)] autorelease];
self.navigationItem.leftBarButtonItem = clearButton;
When I click and launch action sheet:
- (IBAction)ClearHistoryAction:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:#"Clear History?"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"OK"
otherButtonTitles:nil];
// use the same style as the nav bar
actionSheet.actionSheetStyle = self.navigationController.navigationBar.barStyle;
[actionSheet showInView:self.view];
[actionSheet release];
}
if select ok do this:
- (void)actionSheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger) buttonIndex
{
if (!buttonIndex == [actionSheet cancelButtonIndex])
{
//do what i want here!
}
}
In the header file, UIActionSheetDelegate is included in #interface.
Late but, a possible Explanation could be :
Seems to be an issue with the tabbar. If you call UIActionSheet's
[sheet showInView:self.view]
from a view controller that is a child of a UITabViewController, then
the hit testing on the cancel button fails in that portion of the
UIActionSheet that lies above the tabbar's view.
If you instead pass in the UITabBarController's view, then the UIActionSheet acts as expected.
[sheet showInView:self.parentViewController.tabBarController.view];
A more detailed explanation here:
UIActionSheet cancel button strange behaviour
I don't know if it'll solve this problem but you'll want to do buttonIndex != [actionSheet cancelButtonIndex] (check not-equal) instead of !buttonIndex == [actionSheet cancelButtonIndex] (invert buttonIndex (!) and check if that's equal).
You need to use showFromBarButtonItem instead of showInView. The problem is that the cancel button is being covered by another view--maybe a toolbar or tabbar--so it's not getting the touch events you think it should get. There are also showFromTabBar and showFromToolbar that should sometimes be used (see the UIActionSheet class reference).
On the iPhone, in the Calendar App when you press the "Delete Event" button a confirmation slides in from the bottom. Does anyone know of any example code for this, or is it just a short view presented modally with a custom background?
If this is made using a custom view, do you know where I can get a background graphic the same as the one used in the Calendar App?
Thanks in advance!
NB: I am not talking about a UIAlertView dialog box, but the slide-in confirmation with multiple buttons.
UIActionSheet is what you are looking for.
Here is some code example to get you started with:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Save photo?" delegate:self cancelButtonTitle:#"No" destructiveButtonTitle:#"Yes" otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
This will slide in an action sheet from the bottom. It has 2 buttons. Yes and No.
When a user selects any button the actionSheet:didDismissWithButtonIndex: method gets called
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
//your code here
}
Your controller class will have to subscribe to the < UIActionSheetDelegate > protocol
Hope this helps!
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"title" delegate:self cancelButtonTitle:#"cancel" destructiveButtonTitle:#"destructive" otherButtonTitles:#"other", nil];
[actionSheet showInView:self.view];
[actionSheet release];