Working With Stacked UIButtons - iphone

Hey guys, so I have this search bar in my view along with many buttons below it. So when the search bar is tapped, a keyboard pops up, however I want the user to be able to click anywhere below the search bar and above the keyboard to get out of searching mode. I have been scavenging SO for a bit and came across a solution that suggested that I create an invisible button which intercepts touch events which I can use to resign first responder status from the search bar. And I can merely hide/disable the button when I do not need it so that the buttons below it may be tapped right? Wrong. setHidden nor setEnabled: aren't doing the trick. Here is the relevant code:
//touch event on button outsideSearchBarButton which is invisible
- (IBAction)selectOutsideSearchBar:(id)sender {
NSLog(#"Selected outside search bar");
[searchBar resignFirstResponder];
[outsideSearchBarButton setEnabled:NO];
[outsideSearchBarButton setHidden:YES];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)aSearchBar {
NSLog(#"searchbarTextDidBeginEditing");
[outsideSearchBarButton setHidden:NO];
[outsideSearchBarButton setEnabled:YES];
}
Setting the button to disabled or hidden via nib file does not help me at all. Either the button never exists (I can't click between search bar and keyboard and have keyboard go away) or always exists (I can't click any of the buttons below this invisible button). Any help appreciated. Thanks in advance!

//touch event on button outsideSearchBarButton which is invisible
- (IBAction)selectOutsideSearchBar:(id)sender {
NSLog(#"Selected outside search bar");
[searchBar resignFirstResponder];
outsideSearchBarButton.userInteractionEnabled = NO;
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)aSearchBar {
NSLog(#"searchbarTextDidBeginEditing");
outsideSearchBarButton.userInteractionEnabled = YES;
}
Do this.

go to the interface builder and select the button on which you are removing the keyboard during search, then select layout from the above menu and select send to back.Then in the inspector window set the button style to custom.
Hope this helps you.......

Related

How To Resign The UITextView With Done Button

i was wondering if any of you knew how to get access to that done button that appears above the keyboard when editing.
I have seen it before, above the keyboard there is a transparent black area and on the right there is a blue "Done" Button.
I could do this by hand with my own animations and buttons above the keyboard in my app to resign the UITextView, but i would prefer to use Apple GUI elements that people know.
So does anybody have any information about where this "Done" button comes from?
You don't really "get access" to that button, but through the UITextViewDelegate protocol, you essentially can:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html
Implement the
- (void)textViewDidEndEditing:(UITextView *)textView
routine, and assign the UIViewController holding the textview to the textview' delegate.
Inside of that routine, you can do what you wish! You will need to call the
resignFirstResponder
method.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/resignFirstResponder
You will have to implement the style of keyboard that implements that blue done button.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITextInputTraits_Protocol/Reference/UITextInputTraits.html#//apple_ref/occ/intf/UITextInputTraits
FINAL ANSWER
- (void)textViewDidEndEditing:(UITextView *)textView{
[textView resignFirstResponder];
}

How to call numpad using action button not from text field

I know this is silly question but as a beginner at xcode, and i can't find the answer from any source, can i call numpad (numberic keyboard) from my action button? I just want my action button can call numpad like text field do. what code should i insert in my action button?
my code:
- (IBAction)setLoopBtn:(id)sender
{
}
Thank you again for sharing your knowledge to noob like me.
Create a UITextField with a frame that puts it off the visible screen. Assign the type of keyboard you want to display as the default for that field. When the button is tapped, send becomeFirstResponder to your off-screen field.
-(IBAction) ButtonClick
{
txtField.keyboardType = UIKeyboardTypeNumberPad;
[txtField becomeFirstResponder];
}

iPhone - Change UISearchDisplayController "Cancel" button text

Sort question:
Is there a way to change the "Cancel" button text within a UISearchDisplayController to "Done" or "Close"?
Rationale:
I have a UITableView that contains a list of options, each option can be checked or unchecked.
I want to enable search through these options, so I've created and added a UISearchDisplayController.
The user will search for an item, and then perform actions on the items in the search results (i.e. will select/unselect certain items).
Once this is completed the user will then go back to the previous (unsearched) list of options.
The problem is that the only way to dismiss the UISearchDisplayController is to press the "Cancel" button. However "Cancel" is the wrong word here as the actions conducted while within the Search bar will be stored.
Therefore, is there a way to change the "Cancel" button text to "Done" or "Close"?
I found one way to do this, in the delegate for the searchbar, create an empty animation then after a small duration, change your things on the button, this might be because the cancel button is animated in sometime shortly after the delegate is called, thus you cant grab it and change it before that:
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController*)controller {
[UIView
animateWithDuration:0.05 animations:^{} completion:^(BOOL finished){
for (UIView *possibleButton in controller.searchBar.subviews)
{
if ([possibleButton isKindOfClass:[UIButton class]])
{
UIButton *cancelButton = (UIButton*)possibleButton;
//TODO:
// do things with button here...
}
}
}
];
}

Cocoa Touch - UISearchBar Keyboard - Hide 'Search' Button

On my iPhone app I'm using a UISearchBar (without a Search Display Controller). I have my own 'Search' button as a UIButton and therefore on the keyboard that pops up when editing begins on a UISearchBar I would like to constantly hide the 'Search' button on it as it is unusable. How could I go about doing this without the Search Display Controller?
Or instead - is it possible to continue using my UISearchBar and UIButton 'Search', and also get the keyboard 'Search' button to work as well? I have tried -
(void)searchBarSearchButtonClicked:(UISearchBar
*)searchBar
However my UISearchBar is called 'searchbar' and therefore isn't responding to that (changing the searchBar to searchbar doesn't work either). When I instead use a UISearchBar with a Search Display Controller is works perfectly - however, I don't want the new table view that it opens on editing - or is there a way to prevent this too?
Thanks in advance!
Benji
--EDIT: SOLVED. I just used a textfield instead upon the searchbar so it looks similar.
SOLVED. I just used a textfield instead upon the searchbar so it looks similar.
If you want to change UISearchBar's textfield, you may use the following code:
UITextField *textField = [searchBar.subviews objectAtIndex:1];
textField.returnKeyType = UIKeyboardTypeDefault;
textField.leftView = nil;
textField.delegate = self;
But if you want to have an edit bar, a customized one is more appropriate.
For example, create a toolbar and add a UITextField, a Flexible Space and a UIBarButtonItem with text "send" on it. Then it will look like the edit bar in SMS app.

iPhone: is there another way of yielding First Responder status?

Problem: If you have a big form with a lot of text input fields with number pad, you would not want to tell every single text field something like
[myTextField1 resignFirstResponder];
[myTextField2 resignFirstResponder];
instead, it would be great to just tell for example an invisible background button, that it is the First Responder as soon as the user tabs outside of any text field.
Like in JavaScript, when you give an element the focus(), all others lose it. How can I do that in UIKit?
[button becomeFirstResponder];
In your header file, paste this: -(IBAction)backgroundClicked:(id)sender;
in your implementation file, paste this:
(IBAction) backgroundClicked:(id)sender
{
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
In InterfaceBuilder, create a button that covers the entire view.
with the button selected, click Layout > Send to Back
Control drag from the button to File's Owner and select the outlet called: backgroundClicked.