I have a custom UIScrollView , some UIView like collectionView. I wanna use UISearchBar and SearchDisplayController to search and display the content like the application screen on Mac OS below:
Anyone know this? Please help.
For this, Leave the UISearchBarController. Use UITextField or UISearchBar and implement shouldChangeCharactersInRange method if you use UITextField for Search.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
return YES;
}
When you get the object in the Filtered Array. Use any GirdView for showing your result. You can also use UICollectionView too. or some third party Libs, Like CHGridView.
Related
I read some similar questions about this on Stack Overflow, but none of them had a satisfying answer.
What I am trying to achieve is a "Facebook Sign In Button" from the Settings screen.
I want to achieve this using Static Cells.
But I soon discovered that I could not connect a "Action" to the UITableViewCell using Xcode.
I then tried to achieve the same result using a Custom UITableViewCell with a UIButton inside, but it resulted it a lot of extra styling trouble to make it look exactly like a real UITableViewCell.
Now I managed to make the UITableViewCell to behave like a Button using the following solution:
I changed the Identifier of the "Login Button" UITableViewCell to "loginButton". And I added the following code to the Table View Controller.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[selectedCell reuseIdentifier] isEqualToString:#"loginButton"]) {
NSLog(#"Clicked");
// Execute function to run code for Login button
}
}
Instead of executing a IBAction (which would have been the case if I could just link it like a button in Xcode) I am now going to execute a Function.
This is working like expected. But the reason I created this question is: I want to know if this is the right way to go. Is this ok? Is this bad? Why is this ok or bad? Is there a better solution? Thanks!
Thats a reasonable way to go.
A similar solution using indexpaths would be:
Create an outlet for the Table View Cell from IB.
#property (strong, nonatomic) IBOutlet UITableViewCell *loginButtonCell;
Then implement the didSelectRowAtIndexPath: method.
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath isEqual:[tableView indexPathForCell:self.loginButtonCell]])
{
// This will get called when you cell button is tapped
}
}
You can then re-order and without having to modify your code
I have looked at all the similar questions and they are different than from what I am asking. I need to catch a change in the actual text in the UITextField, not just the state of editing. It will be a first responder when the view loads, and I need to know when text is entered so that I can enable "Next" in the navigation bar. Please help me if you can it's really holding me back in my project.
Addition: I am currently using - it doesn't work:
[textField addTarget:self action:#selector(textFieldDidChange) forControlEvents:UIControlEventValueChanged];
Implement UITextFieldDelegate protocol, and respond to the textField:shouldChangeCharactersInRange:replacementString: method.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)replacementStr {
// Enable "Next" if you like what's entered in the replacementStr
}
Check the developer documents for UITextFieldDelegate, specifically this method
i am adding the textfield on each row inside the cellforrow method of tableview,but when i type anything on any textfield ind try to resign textfield on view touch, but it only works for last row's textfield only. what is the solution for that issue,
please help.
Thanks
Dhananjay
if i understand you correctly this will probably work:
add the protocol to your viewController in question and add
- (void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
// custom code
}
afterwards make sure that each textField has your viewController as delegate.
I am using XCode 4.2 .
is there a way to push the UITextField up when the user is entring text ?
the problem is that the UITextField is located behind the keyboard when it appears ...
Thanks
The one way is to simply manually shift the uitextfield up. You can simply use the delegate methods for uitextfielddelegate on begin editing and end editing to do your transformation.
Follow this.
Here is a simple tutorial on how to animate the textfield up when the keyboard comes up. The idea is to implement the UITextFieldDelegate methods like this
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// ANIMATE TEXTFIELD UP
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
// ANIMATE TEXTFIELD DOWN
}
The tutorial has all the details along with working code.
I made a text field but I didn't use Interface Builder, I did it programmatically in Xcode. So now I need a programmatic way to make it resign first responder so that the keyboard will go away when the user presses enter.
[textField resignFirstResponder];
docs
if you want it to go away when enter is pressed, you will need to implement
- (BOOL)textFieldShouldReturn:(UITextField *)textField
in your UITextFieldDelegate
As addition to cobbal's answer, don't forget to set text field's delegate to the class that implements
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
Adding descriptor to that class interface declaration is also a good thing.
I had this question my self and I realize that the above answer may not be what you're asking. My guess is you are adding UITextField as subviews to some view when you 'say double tap' (or some other event). It is important to make a controller the delegate of that subview.
-(void)handleDoubleTapGesture:(UITapGestureRecognizer *)gestureRecognizer{
//some other code creating the textfield
[aTextField setDelegate:self];
In this case I've used the controller itself.
Now inside that controller I can implement
-(BOOL) textFieldShouldReturn:(UITxtField *)textField
and it will work.