UIKeyboard get resign on UIAlertView button index click - objective-c

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];
}

Related

Tapping on a UIButton and hide KeyBoard in iOS7

I have a login screen,when all UITextField are filled user will tap on UIButton for Sign me in. If user tap on background the keyboard will be hide.
But i want to hide keyBoard when user clicked on UIButton which is sign me in button.When UIButton action TouchUpInside called,at that time i want to hide the keyboard. I do not want to hide keyboard on the tap of anywhere in the view.
Thanks in advance.
Call [yourTextField resignFirstResponder]; in your loginAction
- (IBAction)loginAction:(id)sender {
[yourTextField resignFirstResponder];
// your rest code goes here...
}
Just add this to the method in which you use the button for example:
- (IBAction)yourButtonMethod:(id)sender {
// Your operations
[self.yourTextFieldName resignFirstResponder]
}
Note: You must set delegate to self
Eg:
yourTextField.delegate=self;
Then:
- (IBAction)HideKeyBoard:(id)sender
{
[yourTextField resignFirstResponder];
}
just call resignFirstResponder on you textfield. like
[myTextField resignFirstResponder]; in IBACtion of button.

MGSplitViewController won't dismiss itself when master button is clicked a second time

This is basically in continuation of: Dismissing iPad UIPopoverController when BarButtonItem is pushed while it's open, however I see the issue as large enough that it warranted another question.
Basically, they wanted to show the popover when the barbuttonitem (provided by the splitviewcontroller) is clicked, and then hide the popover when the same barbuttonitem is clicked again. They solved it by calling:
- (void)splitViewController:(UISplitViewController*)svc popoverController:(UIPopoverController*)pc willPresentViewController:(UIViewController *)aViewController{
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
}
However, I've come to the problem where on the first click of the barbuttonitem, this method is called correctly and it displays the popover. However, on any subsequent clicks of the barbuttonitem while the popover is open, this method is not called.
More puzzling, when I close the popover view through other means (clicking outside of the popover), then the popover closes automatically. However, a click on the button itself does not close the popover, nor does it call that "willPresentViewController" method.
Are there other means of catching this button click action? Or any thoughts on why the method is not called on a click of the button while the popover is open?
So it seems a normal UISplitViewController automatically closes when you click the "master" button a second time, however, I'm using an MGSplitViewController. So I modified MGSplitViewController.m (specifically showMasterPopover:) to handle dismissing itself when the button it clicked a second time as follows:
-(IBAction)showMasterPopover:(id)sender
{
if (_hiddenPopoverController && !(_hiddenPopoverController.popoverVisible))
{
// Inform delegate.
if (_delegate && [_delegate respondsToSelector:#selector(splitViewController:popoverController:willPresentViewController:)])
{
[(NSObject <MGSplitViewControllerDelegate> *)_delegate splitViewController:self popoverController:_hiddenPopoverController willPresentViewController:self.masterViewController];
}
// Show popover.
[_hiddenPopoverController presentPopoverFromBarButtonItem:_barButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else if(_hiddenPopoverController && _hiddenPopoverController.popoverVisible)
{
[_hiddenPopoverController dismissPopoverAnimated:YES];
}
}

Can you stop a modal view from dismissing?

I have a view that uses a modal view with a page curl to allow for a username to be entered. This username is then verified with a web-based service to see if it is valid.
Everything works great until you enter an invalid username and click outside the modal view. This still checks the username, which is reported invalid and a UIAlertView opens. However, it goes back to the parent view.
Is there any way to get the modal to not dismiss in this case?
I have tried to reload the view but either it isn't working or the UIAlertView is blocking it. The last idea I have is to couple displaying the modal view with the "OK" on the alert for an invalid username. Anyone have any ideas?
If you were not using a UINavigationController You could put something like this in the view controller that calls the modal view:
-(void)dismissModalViewControllerAnimated:(BOOL)animated{
if (_someFlagForBeingProperlyLoggedIn) [super dismissModalViewControllerAnimated:animated];
}
When you tap on the page curl the presenting/parent view controller is sent dismissModalViewControllerAnimated:.
Since you are using a navigation controller your options are limited. This is because UINavigationController is a subclass of UIViewController, and a self centered one at that. When you click the page curl it's dismissModalViewControllerAnimated: is being called.
You still have the option of subclassing UINavigationController and implementing the above method, but that will get messy in a hurry.
Having the UIAlertView "direct back" to the modal login view IS very easy. Have that main view conform to the UIAlertViewDelegate protocol. When you display the alert set that instance as the delegate, and in that class implement the method:
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
// Enclose in if (buttonIndex == #) for selective calling
UINavigationController* nav = (UINavigationController*)[[UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"Preferences"];
[nav setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self.navigationController presentModalViewController:nav animated:YES];
}
Then when the alert view is dismissed it will show the 'login' view.
You should redisplay your modal view with a little delay, something about 0.3-0.5. that's the amount of time needed to alert to be dismissed and that is exactly animation(the dismissing of the alert view) that prevent the modal view from showing up.
-(void)showModal{
SomeModalViewClass* modalView = [[SomaModalViewClass alloc]init];
[self setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:modalView animated:YES];
[modalView release];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
//check the button index if needed and then
[self performSelector:#selector(showModal) withObject:nil afterDelay:0.3];
}

How to dismiss keyboard when the UISearch Bar 'Search" button is pressed?

I've implemented a UISearch bar with the searching functionality set up, however when I press the "Search" button on the keyboard that shows up nothing happens. How can I get the keyboard to hide when the "Search" button is pressed while keeping the text in the search bar intact (To keep the search results present)?
From Text, Web and Editing Programming Guide for iOS:
To dismiss the keyboard, you call the resignFirstResponder method of the text-based view that is currently the first responder.
So you should do this in your UISearchBarDelegate:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
// Do the search...
}
Swift 4
Make sure you have UISearchBarDelegate defined in your UIViewController
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}

UIActionSheet and UIAlertView focus on iPad

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.