Can anyone help me out, i am working with UISearchBar and want that when i write anything in SearchBar and press enter key, it will start desired operation...
I have read searchBarSearchButtonClicked function will get called once the “Search” button will be clicked on the pop-up keyboard window. But it is not called:(
I have implemented as:
(void) searchBarSearchButtonClicked:(UISearchBar*) searchContact
{
//do some thing
}
i have checked by placing breakpoints infact this function is not being called....
any idea??
Thanks!!
Did you assign delegate to that viewcontroller which implemented "searchBarSearchButtonClicked" ?
You need to assign delegate like this.
searchBar.delegate =self;
You need to implement the UISearchBarDelegate protocol and set the delegate of the textfield to the class which implements this protocol.
This is the reason why the delegate is not getting called.
You can try this,
In IB set the delegate to file's owner and implement the delegate.
In Code, if you hold reference to the search bar, then on viewDidLoad
searchBar.delegate = self;
Related
I want my UITextField's keyboard to stay open for the entire time I use this view controller. I don't want it to only open when my user touches the text field. In order to do this, I was hoping I would call the textFieldShouldBeginEditing method by doing this:
EDIT: thanks everyone, I just noticed I called my UITextField a UIImage field for some reason in the interface.
The textFieldShouldBeginEditing delegate method is not something that you call from your code. The OS calls the method when that particular event occurs, and you put code in there to run when the event is fired (similar to putting code in viewDidLoad for your view controller).
To show the keyboard whenever the view controller appears, simply call the UITextField's becomeFirstResponder method in the view controller's viewDidAppear method like this:
[self.myTextField becomeFirstResponder];
Don't forget to create an IBOutlet parameter for the UITextField, link it in Interface Builder, and replace self.myTextField above with the outlet that you created.
You should trigger your textview in viewDidAppear method:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.myTextField becomeFirstResponder];
}
In brief:
In ClassA_VC I do:
ClassB_VC *classB_VC=[ClassB_VC alloc]initWithNibName:#"ClassB_VC" bundle:nil];
[self.view addSubview:classB_VC.view];
Then in ClassB_VC I have an UITextField. I set the delegate connection between textfield and File's owner in IB, I added in #interface declaration and I wrote the protocol methods (textFieldDidEndEditing, textFieldDidBeginEditing, etc...) as usual.
This should work but I got an Exception when I touch the textfield. It seems textfield is not reaching its delegate.
However, if I present the view using presentModalViewController, everything works fine. I'd prefer not having to do it so because these views are into a tabViewController and I'd like not hiding the tabBar when showing.
I hope you understand what I'm trying to say. My english is not very good.
Have you retain ClassB_VC in ClassA_VC?
remove the delegate from interface builder and do this :
ClassB_VC *classB_VC=[ClassB_VC alloc]initWithNibName:#"ClassB_VC" bundle:nil];
[classB_VC.yourTextField setDelegate:classB_VC];
[self.view addSubview:classB_VC.view];
Let me know if it helps
How do I know when the view got closed? Am currently using the delegate pattern, capture viewDidDisappear to fire the event... Is this the correct one to use? Downside of viewDidDisappear is that when my view move to a sub-view the event still fires.
Its a custom view that i made that exptend UITableViewController... In that table you got a list of options that you manage, so when moving between those screens I don't want my event to fire.. I only want it to fire when I close the actual view.
now just see when your UITableView begin open at that time you set the bool value like...
first define this variable global in your .h file like bellow
BOOL isTableOpen;
and after that in your .m file
set yes when your tableview is open with button tap event or anything else which you used...
isTableOpen = YES;
after when your pop-up view or UITableview closed at that time set value NO like
isTableOpen = NO;
and check in your viewDidDisappear: that if isTableOpen is true then do nothing otherwise yes...
-(void)viewDidDisappear:(BOOL)animated{
if(isTableOpen){
//call your method which you want...
}
}
i hope this help you or get some Idea ..
:)
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;
}
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).