iPhone AlertView Text Field Keyboard not visible - iphone

I have an alert view with a uitextfield added as a subview.
In my uitableview controller the keyboard shows fine.
However in a different view I wanted to do the same thing. So instead of using a UITableView Controller I made it a UIViewController so that I could add a toolbar at the bottom of the view.
But when I display the UIAlertView the keyboard is hidden. I'm thinking it's behind the view because the alert view moves up to make room for the keyboard.
Any ideas?
UPDATE:
The reason the keyboard was being hidden was because I was dismissing a modalviewcontroller after showing the alert. For some reason it would dismiss the keyboard also I guess. Just rearranged the order an fit works fine now...

Try implementing the didPresentAlertView: method and inside set the text field to firstResponder like so:
- (IBAction)someActionThatTriggersAnAlertView:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"TITLE" message:#"MESSAGE" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Done", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *someTextField = [alert textFieldAtIndex:0];
someTextField.keyboardType = UIKeyboardTypeAlphabet;
someTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
someTextField.autocorrectionType = UITextAutocorrectionTypeNo;
[alert show];
[alert release];
}
#pragma mark - UIAlertViewDelegate Methods
- (void)didPresentAlertView:(UIAlertView *)alertView {
[[alertView textFieldAtIndex:0] becomeFirstResponder];
}
UIAlertView Documentation
UIAlertViewDelegate Documentation

Related

UIAlertView not showing message text

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");
}
}

How to show an AlertView with another AlertView

I want to show nested alertViews. Problem, which i am facing in nested alertViews is that when i click an "add" button of first alertView it shows the second alertView, in second alertView i have a textField and a "Save" button. I want to save data when i click on save button and then reload UITableViewData, which is already in the first alertView.
I am new in iphone, so please help me.
You should create your alert views with different tag property so that in delegate method you can easily differentiate which alert view is appeared on the screen.
For example :
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Info"
message:#"Message" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil] autorelease];
[alert setTag: 1001]; // give different tag to different alert views
[alert show];
[alert release];
Now in delegate method :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 1001)
{
// do something
}
eles if (alertView.tag == 1002)
{
}
}
Hope it helps you..

Problem in navigation Controller

I have a problem I want to control the backBarButtonItem when I click on it Action backAction "works
my problem is that SetAction does not work, I hope there is a solution for the controller backBarButtonItem
- (void)viewDidLoad {
[self.navigationItem.backBarButtonItem setTarget:self];
[self.navigationItem.backBarButtonItem setAction:#selector(backAction)];
[super viewDidLoad];
}
- (void)backAction {
if ((isSaveCarte==NO)&&(isNewCarte)) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Voulez vous Enregistrer la Carte" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Save",nil];
[alertView show];
[alertView release];
}
}
Check below, Could be useful for you
How to trap the back button event
http://forums.macrumors.com/showthread.php?t=637266
How to create backBarButtomItem with custom view for a UINavigationController
Assignig a action to backBarButtonItem
back bar button item is meant for navigating back...
why don't you use the leftBarButtonItem instead of backBarButtonItem..
the only difference would be it wont be a left pointed button.. but you are not navigating back anyways right?

iPhone, I want to create a popup menu from my tab bar, but what are they call, like copy / paste?

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.

UITextField and UIPickerView

Is it possible for a UIPickerView to appear instead of a keyboard when a UITextField is selected? Every option in Interface Builder is some sort of keyboard.
I suppose I could create a UIPickerView programmatically and create one when the UITextField registers a touchUpInside event, then tell the UITextField to resignFirstResponder, but that seems a bit of a hack.
Is there an "official" or more "correct" way to do this?
Thanks!
You can implement this code and override the default behaviour (that is, showing the keyboard):
#pragma mark -
#pragma mark UITextFieldDelegate methods
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:#"Bouh!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return NO;
}
Instead of showing a UIAlertView, you might as well show your own UIPickerView and do your thing.