Xcode search bar not running function - iphone

I am going crazy with this search bar in storyboards and have been trough loads of tutorials.
I have a search bar on my view and set it as an outlet
IBOutlet UISearchBar *searchBar;
how do I run code when the user clicks 'DONE' on the keyboard. I have tried this but nothing works
- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {
NSLog(#"Hello");
[searchBar resignFirstResponder];
}

I haven' used the storyboards for XCode, but have you made sure to set the viewController as the searchBar's delegate?

searchBarSearchButtonClicked should work, but have you tried searchBarResultsListButtonClicked and searchBarTextDidEndEditing. Btw, is this iphone or ipad? and check your delegate is set correctly.

Related

UITextView not becoming first responder in ios 7

I am using the following control in a viewcontroller i want to show the keyboard when user opened the view so I tried to call this method from the viewcontroller
[self.inputToolbar.textView becomeFirstResponder];
But the keyboard does not show when opened the view. So i called the becomefirstresponder in the place where the textview is allocated you can see the allocation page here i called like this
[internalTextView becomeFirstResponder];
Now it works in iOS6 but in iOS7 it does not works
By using sample code
I write below code inUIInputToolbarViewController.m > loadView
[self.inputToolbar.textView.internalTextView becomeFirstResponder];
And it's working fine.
Code

Disabling the keyboard interaction in a Text View in iOS5, XCode 4.3.2

Can someone please tell me how to disable the keyboard in a Text View? Whenever I click on words, the keyboard pops up and I am able to manipulate my original text. I just want it to be selectable, so you can copy, paste. I prefer this to be disabled for the whole app. If someone could tell me how and where to implement this I would really appreciate it.
ThX
I think it's in the inspector isn't it?
For disabling using code, use the below given code.
Inherit UITextFieldDelegate protocol In your view controller add the text
#interface YourViewController () <UITextViewDelegate>
In viewDidLoad set yourself as a delegate:
yourUITextView.delegate = self;
Implement the delegate method below:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
return NO;
}

backgroundTouched not working in uitableviewcontroller iphone

my code:
.h:
- (IBAction)backgroundTouched:(id)sender;
.m
- (IBAction)backgroundTouched:(id)sender {
[textField resignFirstResponder];
[self.view endEditing:YES];
NSLog(#"backgound taped");
}
I dont know why the backgroundTouched not called when i tap the background and the keyboard not hidden. I think never called because of wiring up code problem.
Neither Both textField resignFirstResponder and self.view endEditing:YES nor NSLog is working.
Can anyone let me know how to do this? or What am i missing here?
Im trying to hide the keyboard after done writing in uitextfield, the textfield is inside uitableview cell.
P.S i made it in uitableviewcontroller without xib file
Thank you.
Instead of a backgroundTouched method (which I have no idea how it gets actually called), consider using the delegate method for UITextField, namely textFieldDidEndEditing: (I've linked Apple's documentation for you).

viewWillAppear not fired up from UITabBarController in 4.3 but works fine in 5.0

Yes, I know that it's not a good idea to call UITabBarController via
[self presentModalViewController: animated];
I have custom UITabBarController with hidden original TabBar and my own TabBar. I use this controller to choose for example song as in iTunes - by singer, by album, by something else. Then when user select one from any tabs I dissmiss this modal view controller and return to main view.
I started developed this with simulator iOS5 and all was fine - viewWillAppear was fired up in all my tabs tableviewcontrollers which I called from tabbarcontrooler [self setSelectedIndex:X];
But then I tried to run my code in 4.3 simulator and device and discovered viewWillAppear never fired up in my tabs at all.
How can I fix this? thx
Update: I use [self presentModalViewController: animated]; to call new UIViewController *controller, where I initiate UITabBarController and place it's view as subview. [controller.view addSubview:myTabBarController.view];
In your UIViewController, add the following :
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[myTabBarController viewWillAppear:animated];
}

How to have UISearchBar scope bar always visible?

Here's my latest problem with the iPhone SDK.
I've got a UISearchBar and its delegate all set up.
Also, when I load my view, I call
self.searchDisplayController.searchBar.showsScopeBar = YES;
That way, when my view is first presented, I see the scope bar, as expected.
But if touch inside the search bar and then outside it (or even if a perform a search and then cancel it), the scope bar gets hidden again.
So my question is: is it possible to have the scope bar always visible? Even after performing searches?
Thanks a lot.
The UISearchDisplayController is hiding the scope bar for you.
The way around this is to subclass UISearchBar and override the implementation of setShowsScopeBar:
#interface MySearchBar : UISearchBar {
}
#end
#implementation MySearchBar
- (void) setShowsScopeBar:(BOOL) show
{
[super setShowsScopeBar: YES]; // always show!
}
#end
Then, in Interface Builder, change the class of the Search Bar you have in your view (that is associated with the UISearchDisplayController) to the new class type -- MySearchBar in this example.