I need a help . Actually when I tap or click on search button then I should get a black screen . As you could see using in ABPeoplePicker.So it is possible with UITableView ? I've added an image that can help you in getting my question.
here is my code :-
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
if(searching)
return;
[searchBar setShowsCancelButton:YES animated:YES];
searching = YES;
letUserSelectRow = NO;
[contactTableView setScrollEnabled:NO];
}
![Example image][1]
If you add a UISearchDisplayController instead of a UISearchBar, the black screen will come automatically. If you need it in some other places than UISearchBar, you have to add view with black background color and show/hide it when needed.
Related
I have a UISearchbar with searchDisplayController that drag to my tableview via IB. My search scope bar hidden when it's not in search mode. When I start to search the scopebar will show like the image below
then I type my text and search result it show when I scroll the result scopeBar hide like this
so what should I do to show the scope bar when scroll ?
this is my code:
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
controller.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
controller.searchResultsTableView.bounces = NO;
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
self.searchDisplayController.searchBar.showsScopeBar =YES;
[self.searchDisplayController.searchBar sizeToFit];
[self.searchDisplayController.searchBar setShowsCancelButton:YES animated:YES];
return YES;
}
I found my problem
In
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
I set the
self.searchDisplayController.searchBar.showsScopeBar
to NO. so when I scroll the tableview this method call and hide the scopebar
I have a subclass of UITableViewCell with added UITextField to edit the contents of a cell in editing mode.
In my custom cells implementation I have overridden setEditing like this:
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
if ([self.textField isFirstResponder])
[self.textField resignFirstResponder];
NSLog(#"%#",self.textLabel.text);
if (editing) {
self.textLabel.hidden = YES;
self.textField.hidden = NO;
}else{
self.textLabel.hidden = NO;
self.textField.hidden = YES;
}
[super setEditing:editing animated:animated];
}
And what happens is when I call setEditing for first time they all go to editing mode. But if I try to modify cell and if this cell goes offscreen and I tap the "Done" button the cell is still in editing mode. Only the cell that has gone offscreen. If it's visible onscreen when I tap the "Done" button it just works.
Here is a video to better describe the problem: video on Dropbox
You can solve this in your UITableViewController subclass by implementing the following:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
//since setEditing isn't called on cells that are offscreen do this to ensure the keyboard is dismissed.
[self.view endEditing:editing];
}
You may try to dismiss the keyboard when the textfield goes off screen
Is there a possibility to reset a UISearchbar with searchDisplayController programmatically which is active and already contains text?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.searchDisplayController.searchResultsTableView) {
searchDisplayController.searchResultsTableView.hidden = YES;
searchBar.showsCancelButton = NO;
[searchBar resignFirstResponder];
}
}
This solution is working, but there is still text in the searchBar. If i add those lines of code:
searchBar.text = #"";
There is always a black transparent view left.
Any solutions?
Here ya go. This is a delegate method called when the user hits cancel. If you want to wire it up differently just declare your search bar as an outlet and reference it. Anyway:
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
searchBar.text = #"";
[searchBar resignFirstResponder];
}
Pretty sure what you're looking for is UISearchDisplayController.active
From the SDK:
#property(nonatomic, getter=isActive) BOOL active
If you set this value directly, any change is performed without animation. Use setActive:animated: if a change in state should be animated.
When the user focus in the search field of a managed search bar, the search display controller automatically displays the search interface. You can use this property to force the search interface to appear.
This thread is so old it has dust. Still here we are in swift so
<#your UISearchController variable#>.isActive = false
don't you have to retire the firstResponder
[self.searchBar resignFirstResponder]
You can also explicitly hide the resultsTableView, if that's what you want:
searchDC.searchResultsTableView.hidden=YES;
(searchDC is an instance of UISearchDisplayController)
This will help you with hiding the Cancel button and stuff: http://www.alexandre-gomes.com/?p=418
I have a bug in an app I'm working on regarding a UISearchBar.
Using the code:
int width = 250;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(768 - width - indent, companySelectionButton.frame.origin.y + (companySelectionButton.frame.size.height - 44)/2, width, 44)];
[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];
[searchBar setPlaceholder:[Globals localisedString:#"Search by Code or Name"]];
[searchBar setAutocorrectionType:UITextAutocorrectionTypeNo];
[searchBar setDelegate:self];
[self.view addSubview:searchBar];
[searchBar release];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
The search bar is in the position I want in both orientations, but it won't respond to taps in landscape and become first responder/show the keyboard.
I've tried commenting out the following lines to see if it helps but it doesn't fix it:
[searchBar setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
Anyone else had a similar issue?
Thanks in advance :)
EDIT
After commenting out [searchBar setDelegate:nil]; the search bar is able to become first responder in all orientations. But of course I need a delegate to be able to use the searchbar! Any ideas??? Will continue to have a play, perhaps I'm missing some delegate method?
Redrawing the frame of the searchbar in willRotateToInterfaceOrientation fixes the issue.
Sorry everyone, I discovered that I was accidentally doing something strange in my searchBarTextDidBeginEditing delegate method that resigned the searchbar as first responder if the device was in landscape.
This question is of no use to any one, should I delete it?
I'm using an tableView with custom cells. When I want to display another view using the pushViewController function of the navigationController I loop through the textfields and call resignFirstResponder on them. But resignFirstResponder does only work when the textfields are being displayed so I scroll first to the top of the page. This is the code:
NSIndexPath *topIndexPath;
topIndexPath = [[NSIndexPath indexPathWithIndex:0] indexPathByAddingIndex:0];
[self.tableView scrollToRowAtIndexPath:topIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
[[self textFieldForRow:0] resignFirstResponder];
[[self textFieldForRow:1] resignFirstResponder];
[[self textFieldForRow:2] resignFirstResponder];
[[self textFieldForRow:3] resignFirstResponder];
This works, but after this my tableView has some weird problem with its origin. I tried to set it's superviews origin to 0, but that doesn't help.
Here is a screenshot of the problem: link
As you can see, my tableview is too large and the scrollbar is stuck in the middle of the view when reaching the bottom.
Sorry for my english, I hope that you can understand me,
Thanks in advance!
Hans
It was actually quite simple. Just put your resignFirstResponder in -viewWillDisappear
edit: this is better and less hacky, I added this to my class, and it worked:
edit 2: seems that your app will be rejected when using the previous code. Here is a updated public api version:
- (void)viewWillDisappear:(BOOL)animated
{
[self.view findAndResignFirstResponder];
}
And:
#implementation UIView (FindAndResignFirstResponder)
- (BOOL)findAndResignFirstResponder
{
if (self.isFirstResponder) {
[self resignFirstResponder];
return YES;
}
for (UIView *subView in self.subviews) {
if ([subView findAndResignFirstResponder])
return YES;
}
return NO;
}
#end
(source: Get the current first responder without using a private API)
I would fix your other problem. I imagine when you say you can't call "resignFirstResponder" when the other textFields are on screen, you mean that there is a crash?
If so, it is because of screen cells don't exist and therefore the textfields are gone as well. They are recycled (so they can be dequeued for new cells).
The easy solution is to only call resignFirstResponder only on textFields that ARE on screen.
What you are doing now seems a little hacky.