Double tap UISearchBar with search delegate on iOS 7 causes UISearchBar to disappear - ios7

We have a search bar in the table header. When the user taps on it twice quickly on iOS 7, it disappears. Does anyone have any suggestions what we are doing wrong?

After lots of trial and errors, I found that when searchDisplayController ends search, searchbar gets disappear, so I have reinserted the searchbar to table header and it worked for me.
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
self.searchingFetchedResultsController = nil;
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[self.tableView insertSubview:self.searchDisplayController.searchBar aboveSubview:self.tableView];
}
return;
}
Hope this helps.

(I posted this same answer to Troubles with UISearchBar \ UISearchDisplayViewController, which seems like a duplicate of this question.)
I encountered the same issue, and noticed that searchDisplayControllerDidEndSearch was being called twice. The first time, the superview of self.searchDisplayController.searchBar is the UITableView, and the second time it's still a UIView.
With Priya's answer, I worry about unintended consequences or unneeded overhead from re-inserting the subview every time the search bar is double-tapped, and I also worry about it breaking with future iOS versions. Fortunately, we can take advantage of the superview strangeness like this:
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
if (self.tableView != self.searchDisplayController.searchBar.superview) {
[self.tableView insertSubview:self.searchDisplayController.searchBar aboveSubview:self.tableView];
}
}
If I had to guess what was happening, the UISearchBar is automatically creating a temporary UIView as its superview when it's active – this is the view seen when the search is being performed. While the UISearchBar is being dismissed, the superview gets set back to be the UITableView it had before, unless it gets dismissed so quickly that it was never properly initialized, in which case it cleans up improperly and the UITableView never gets the UISearchBar back as its child.
This solution still isn't ideal, and I think Apple must be doing something different in its own apps because their search bar UX feels a bit better. I think it would be better not to handle the second tap in the first place until the UISearchBar was ready. I tried using the other UISearchBarDelegate methods to do this, but I couldn't find an appropriate hook to override the current behavior.

Related

UITextField losing firstResponder after view appears

I have a UIPageViewController. One page has a single button, and the other page has a UITextField with a button. When the page scrolls to the view with the field, I'd like it to becomeFirstResponder and open the keyboard. Here's what happens:
I call [self.locationQuery becomeFirstResponder] ViewController's viewDidAppear method. But it never opens the keyboard.
I do the same in viewWillAppear, and it appears briefly, but then is quickly dismissed.
If I'm on the page with the text field, and pull the page partway and let it go (without changing pages), self.locationQuery receives focus just fine.
It seems like something else is grabbing firstResponder status from the field, but I haven't the faintest idea what, and why it would only be happening when the page changed (rather than revealed after a failed page turn). Any ideas?
Update
I created a way to crawl the views to see if any other views were, indeed, taking firstResponder (from an answer to this question: Get the current first responder without using a private API). Results:
When I explicitly give first responder to the text field, the method reports it has first responder status.
When I don't, it returns null.
Now I'm even more confused.
I don't really understand the nature of what was causing my issue, but I was able to fix it by wrapping the call in an async dispatch in viewDidAppear:
dispatch_async(dispatch_get_main_queue(), ^{
MapManualViewController *strongSelf = weakSelf;
[strongSelf.locationQuery becomeFirstResponder];
});
This one stole a few hours from my life. Here is the Swift 3.x implementation.
DispatchQueue.main.async(execute: {() -> Void in
let strongSelf: MapManualViewController = self
strongSelf. textField.becomeFirstResponder()
})
I also put it in viewDidAppear

Weird segue animation in xcode

Ok guys this is killing me. I have 10 "view controllers" in a row across my storyboard. All ten use the same .h and .m file. Each has a segue connecting it to the next one in line. All of the segues have the following identifier: segueToNextPage. I'm calling the segue with this method:
-(void)myMethod {
// other code
[NSTimer scheduledTimerWithTimeInterval:4 target:(self) selector:#selector(nextPage) userInfo:(nil) repeats:NO];
}
-(void)nextPage {
[self performSegueWithIdentifier: #"segueToNextPage" sender: self];
}
On the storyboard I have set the segue's transition to cross dissolve. I have also set the transition style of all "view controllers" on the storyboard to cross dissolve.
The segue works fine when called except it does this corner to corner spin/flip animation not the cross dissolve as i had expected.
I made a test project with just two pages just to be sure that I wasn't losing my mind and everything works as expected if I use this code and connect it to a round rect button:
-(IBAction)nextPage {
[self performSegueWithIdentifier: #"segueToNextPage" sender: self];
}
Can anyone spare the time to explain why my first example doesn't work as expected. It would be greatly appreciated.
I replicated your code and it seemed to work without a problem. The only issue that I can think of is that by defining the "segueToNextPage" segue multiple times in the StoryBoard you are potentially overwriting its definition each time. You should check each one of the transitions and make sure that one of them is not set to "Flip Horizontal"
Im still not sure whats causing this to happen with those ten "view controllers" on the storyboard but making a new .h and .m with the exact same code in it then hooking those to ten new view controllers on the storyboard has fixed the issue. I was even able to copy and paste the contents of the original view controllers into the new ones. Still very strange but for now problem solved.

Force the keyboard to become visible and stay visible in view

I want to have the virtual keyboard appear in my view on load and I want it to say visible for the lifetime of the view. There is a text field and I treat as the primary control for this view.
Initially, I called [self.textField becomeFirstResponder] in -viewWillAppear: following advice I've gotten here. Then, I came up with a different idea: I overloaded UIViewController's -becomeFirstResponder.
- (BOOL)becomeFirstResponder
{
if (self.primeResponder)
return [self.primeResponder becomeFirstResponder];
return [super becomeFirstResponder];
}
I'm not seeing any hidden problems with this, but then again, no one recommends it either. Am I missing something? Is this a bad approach? Please help.
In reviewing my old question, I thought now would be a good time provide an answer to this.
It works and does not have any major drawbacks.
I've had good luck with this method except in a peculiar circumstance. I used this to set a text field in a table view cell as the prime responder. In iOS 6, it didn't load the keyboard or highlight the textfield when the view was pushed onto the navigation controller stack.
See In iOS 6, -[UITextField becomeFirstResponder] doesn't work in -viewWillAppear: for my solution to that problem.

How to hide or remove the UIwebview when a action is done?

I have two IBActions. In one action I am loading the UIWebview to display a PDF File from my bundle. On clicking the other button the whole UIWebView should get removed from superview.
I have tried using:
[webview removeFromSuperview];
and
webview.hidden=YES;
Neither of these are working. They are hiding my UIWebView for a second, but then it appears again.
Is is
I have created UIWEBVIEW programatically and added the UIWebvieWDelegate in the interface file. But when initializing the UIWebView I didnt set webview.delegate=self; Is it the problem?
have you connected Referencing Outlet to the class's #property in the Interface Builder?
If you don't do it, it would be the a possible reason why you cannot reach the UIWebView in your source code. for your sake, you should check the pointer of webview, if it is nil chronically, there is 100% you have not connected them each other.
I was trying to make a thing like this. The solution that worked for me was to add UIview object as subview to view with the frame of webview and bringing it to top.... When u want to make uiwebview visible, just remove that uiview object from superview.
OK, it seems old question, but also i can see there are almost thousand people have view it, and may have the same problem. so my answer for anyone my have the same issue in the future.
I just been doing something smiler and want to hide the web view when at a certain action.
I have tried the following
-(void)viewDidLoad
{
[super viewDidLoad];
process = [ProcessingData new];
[DetailView setHidden:YES];
DetailView.hidden = YES;
[DetailView removeFromSuperview];
self.DetailView = nil;
}
however it is still not working, as i have few labels in the WebView which are don't disappear when the view load, when I looked at the "StoryBoard" i notes that the labels are not subview of the
can u see the hierarchy of the libels under the WebView, they are subview of the main view, where they suppose to be same as the table view hierarchy
so in may case the WebView is hiding but the labels are not as they are not a part of the Webview.
how to sort this problem, if you really don't need web view use the normal one, otherwise you have to hide all the labels in that view. hope thats helpe
I don't know obj-c but still posting a solution that worked for me in swift. basically you have to use the main thread to remove the webview.
DispatchQueue.main.async {
print("\nremoving webview\n")
self.myWebView.stringByEvaluatingJavaScript(from: "document.body.innerHTML='';")
self.myWebView.removeFromSuperview()
}

UIViewController messes up when personal hot spot is turned on

When I turn on personal hot spot connection, my layout gets pushed down. How can I either remove this hot spot bar at the top or get a notification for this bar and rearrange my view according to it? Thanks.
When the size of your status bar changes, your application delegate method is called. All you have to do is handle that selector and update your view manually (if autoresizing isn't something you would go with). Here's what you need to add to your app delegate:
- (void)application:(UIApplication *)application didChangeStatusBarFrame (CGRect)oldStatusBarFrame
{
// update layout here
}
However, as #sosborn has mentioned, it might be a lot simpler to make sure that your views and subviews have autoresizing (aka springs and struts) set correctly (either in code or through the interface builder).
One last note: you can always query for the status bar frame (and therefore size) by calling: [[UIApplication sharedApplication] statusBarFrame]