UIActionSheet and UIAlertView focus on iPad - cocoa-touch

I have some troubles with UIActionSheet and UIAlertView on iPad
in fact, i use an alertView as a pop up with textfields and buttons to enter a
date, when i click on the button the UIActionSheet who contains my UIDatePicker is supposed to show, it shows but i don't have focus to pick a date
the focus is still on the alertview and the ActionSheet is in the background
(but on iphone there is no problem it works fine)
is there some code to add for the iPad?
Thanks for your help

In the clickedButtonAtIndex method of your AlertView explicitly dismiss the alertView and show your ActionSheet.
using;
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated and present the action sheet
e.g
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[alertView dismissWithClickedButtonIndex:0 animated:NO];
if(buttonindex==1{
[self showActionSheet]
}
}
NB for Iphone you may not need to dismiss the alertView.

Related

Dismiss uialertview programmatically in iOS7

I have implemented UIAlertview category in custom class. i am calling that method from my uitableviewcontroller to show an alert .But in iOS7 on iPhone 4 device, that alertview is coming multiple times while fast clicking on the uitableviewcells.
I am trying to dismiss the alertview if it is already opened by using the following code.
for (UIWindow* w in [UIApplication sharedApplication].windows)
for (NSObject* o in w.subviews)
if ([o isKindOfClass:[UIAlertView class]])
[(UIAlertView*)o dismissWithClickedButtonIndex:[(UIAlertView*)o cancelButtonIndex] animated:YES];
But this code is not working in iOS 7. I am not sure the way which i follow is correct or not.
Iterating the through [UIApplication sharedApplication].windows is a bad idea. Better concept is to hold the reference of an active UIAlertView and dismiss it when you want.
Note:
Make use of the UIAlertView property isVisible, which indicates whether the AlertView is displayed.
Example:
if (YES == alertViewInstance.isVisible)
{
//dismiss your alert view
}

UIAlertView Show causing strange behavior with UIButton

I basically have a replica of the iMessage app, but I am getting a strange behavior that the Send button is reverting back to the down position (When keyboard now showing), when I present a UIAlertView.
If I comment out [alert show], the Send button doesn't disappear.
If I do [alert show] the UIButton disappears behind the keyboard.
In the - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex I can press the cancelButton which causes no code in the method to execute, and the button will still disappear.
The only way I can get it to maintain its position is to manually put it back in that position in the - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex. There is no code about the Send UIButton either in any of the UIAlertView delegate methods except when I manually set it's frame back to the correct position.
Is this just a bug in iOS7 or is it something I am doing wrong?
Thanks!

Popovers and not disappearing keyboard

I have a popover that has a textfield on it, when I click on the popover background, the keyboard disappears. However when I click around the popover area, the keyboard doesn't disappear.
Is there a way I can get into the delegate that collapses the popover so that I can add the resignfirstresponder command.
Sure! UIPopoverController has a delegate method popoverControllerShouldDismissPopover: in which you can add the resignFirstResponder command.
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
[self.someTextField resignFirstResponder];
return YES;
}
You can call resign responder methods to the popover dismissal delegate like :
(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
OR
(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController

UIKeyboard get resign on UIAlertView button index click

I create custom UIAlertView and dismiss it on its own custom button, but its also resigning the keyboard from UIWebView load with editable div(I am writing something on it). How can I stop resigning the keyboard.
-(void)dismissAlertView
{
[alertForBuySmacks dismissWithClickedButtonIndex:0 animated:NO];
}

iOS Beginner: UIAlertView Window with 3 Buttons > Check what button was pressed

I have a working code from a tutorial but don't understand it completely.
Situation:
After a button was pressed in my iPhone App
an AlertView appears with three buttons.
Now I like to check what button the user pressed.
CODE FROM THE TUTORIAL:
- (IBAction)infoButtonPressed:(id)sender {
UIAlertView *myAlert1 = [[UIAlertView alloc]initWithTitle:#"My Alert View 1"
message:#"Here we go"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Option1", #"Option2", nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(#"Button: %i, was pressed.", buttonIndex);
}
Code works, I see the correct output in the console as a NSLog but how is it possible
that the method:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(#"Button: %i, was pressed.", buttonIndex);
}
refers to the correct alert view. In this case: myAlert1.
What about with more than one alert view.
For example a second one calling myAlert2.
I know the following code is not correct but it would make more sense to me
if I'd write the method as follow:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(#"Button: %i, was pressed.", buttonIndex_FROM_myAlert1);
}
Hope you can help, drives me nuts.
Regards,
Marc
how is it possible that the method refers to the correct alert view?
For exactly that reason, the delegate method alertView:didDismissWithButtonIndex: actually tells you which alert view it refers to. Note that the method has two arguments. The second one tells you the button index and the first one points to the alert view this button index refers to.
If you have more than one alert view that share the same delegate, you will have to check against the first argument which alert view this is about. To be able to do that, you would have to store the alert views in an ivar/property or other data structure in order to remember them in the delegate method. (Or, since UIAlertView is a subclass of UIView, you could use the tag property to distinguish between multiple views).