I've a view controller (named it as SearchViewController) with UITableView and UISearchBar. UISearchBar is set to table as a header view. While searching in the table using this searchbar works great.
By selecting any one of the displayed search results, I can move to next view (named it as DetailsViewController). But after returning to the SearchViewController, magically the UISearchBar is disappeared and my app is crashed. I found the same code is working fine on iOS 3.1.2 but not on iOS 4.0 (no idea about 4.0.1 or 4.0.2).
I'll be really thankful, if anyone has a work around for this.
I always use an UINavigationBar and an UINavigationItem to display the UISearchBar. Setting the navigationItem.titleView to the searchBar works fine for me. (Don't forget to call [theSearchBar sizeToFit])
Please give us more information on the crash. What is the console output?
Related
I am at a loss with what is potentially a simple fix.
I have a basic ViewController with a UINavigationController, and a UISearchBar embedded.
Basic view layout
When I PUSH a new UIViewController onto the Nav - I get a brief animation issue where a black background appears, and also the cancel button doesn't disappear.
Animation glitch
It's only brief, but annoying enough.
When I return back using the back button, the search bar reverts to white, and then switches to red.
Back display issue
I wondered if I had configured something wrong, so I created a fresh project and left everything with the defaults. Yet I get the same issue.
Stripped back and the same issue
I'm using xCode 9.3 - with swift 4.1
Any ideas?
Check the extendedLayout settings of your view controllers (these can be set in code or in the storyboard editor). They need to be the same for both view controllers or you'll get this animation glitch.
In your case the problem might be the embedded search bar. It seems to be present only for one of the view controllers. You've got navigation bars with two different heights because of that. The framework doesn't respond well to that...
I am programming with Swift for iOS 8.
I would like to have a SearchBar on top of a Table that looks like and behave exactly like the one in Contacts App in the iPhone.
So far I have a UIViewControl embedded in a NavigationController, added an UISearchBar and an UITabelView to the UIViewControl. The Table is populated with data and searching is working. Problem: when I dismiss the keyboard, the Cancel Button is greyed out.
When I add the SearchBar with code and put it in self.tableView.tableHeaderView,
Keyboard and Cancel buttons works as expected but the SearchBar stays not in place when scrolling the tableView.
None of the many tutorials and advices I found solved the problem.
Any advices or tips?
I have two UITextFields inside a static TableView (in a Storyboard) for loggin in. The first time go to the tableView via a modal segue, the TextFields are editable as they should be. When I then go back and forth to that view again, the TextField seem to be non-editable. If I read out the textField.isEnabled, it is set to YES.
Even more strange: this behavior is only with iOS 6.0. On iOS 5.0 everything is fine.
I've already added this in viewWillAppear
TextField.userInteractionEnabled = YES;
I've also commented out all of my viewDidLoad and viewWillAppearCode, but still no avail.
Any idea is welcome.
EDIT: after closing and restarting the app, I once again have one shot. I looks like something is screwed, once I opened and closed the view.
I actually had a very similar problem with my TextFields in one view not being editable after doing a back and forth segue with another view. For me, it was a problem with the first responder status, and things started working fine after adding the following in prepareForSegue:
[self.textFieldName1 resignFirstResponder];
Hope that helps.
I wasn't lucky with searching for this, so here we go ;)
I have a UIViewController with a custom UINavigationBar which pushes another UIViewController as subview.
Everything works fine except when I click the back button on the subview. The previews (first) view appears correctly, but not animated. The animation of the UINavigationBar is correct, only the views switch immediately.
The function - (void)viewWillAppear:(BOOL)animated of the first UIViewController gets called with NO for animated. This only happens when I test with iOS 5, not with iOS 4.
Does anyone know how to fix this?
Thanks for your help! Hannes
UPDATE 1
I just removed all custom code and just used the plain UINavigationBar (so no extra settings) and it still doesn't work with iOS 5. This is my code I use in the first ViewController to push the second ViewController:
[self.navigationController pushViewController:secondViewController animated:YES];
As I already mentioned - when I click the back button in the navigation bar on the second view the first view appears immediately without animation.
Any help would be appreciated! Thanks!
UPDATE 2
I feel like I'm getting closer to the issue, but still no solution:
I just added a custom UINavigationController where I just call [super popViewControllerAnimated:animated]. This get's called correctly (animated is YES) but the viewWillAppear of the first UIViewController gets NO as value for animated...
I was having a similar problem today where the UIViewController was getting NO in viewWillAppear, except with the standard UINavigationBar and UINavigationController.
It turned out to be due to manually calling viewWillAppear:YES somewhere it shouldn't have been. This item suggests that it can also be caused by calling the wrong super method somewhere (e.g. [super viewWillAppear:animated] instead of [super viewDidAppear:animated] inside of viewDidAppear).
As for using a custom UINavigationBar, I ran across this link today that may help your case: http://sloshire1.posterous.com/simple-fix-for-viewwillappear-in-ios5
Apple implemented official ways to create custom navigation bars in iOS 5. Unfortunately, they also broke most of the non-official ways of doing it in iOS 4. iOS 5 won't call drawRect for you anymore. You need to have two ways of doing it, one for iOS 5 and greater, using the new calls, and one for iOS 4 and earlier, using the old calls. Check out the documentation for custom navigation bars in iOS 5 for more info.
Did you try to remove all your custom code and go with the native navigation bar? Does the behavior stay the same? This way you can check if your custom bar messes with the transition.
I have a MKMapView with annotations on it and it works fine. I have a search bar as part of my navigation bar. When a user clicks on the search bar field I wanted to bring up a UITableView in code. I create a UITableView in the initialisation and want to add it to the sub view when - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; gets called.
This all works fine but im trying to add it using [self.view addSubview:tableView] and nothing shows up. I've only ever made table views using UITableViewController so I'm a bit lost.
Thanks
I'd suggest creating a UITableViewController to control it, and then using presentModalViewController:animated: to show the tableview.
This was actually correct. I was just initialising it wrong not setting the bounds for it.