Behaviour of a searchDisplayController.searchResultsTableView inside a UINavigationController logic - iphone

I have a ordinary UITableViewController inside a UINavigationController. The former includes a searchbar which is connected to a search display controller. I use the standard behaviour, i.e. when the user enters any character the search results table view overlays the normal table view.
Now, both table views act inside a navigation controller. If I select one item from the search results table view, a new uitableviewcontroller (with specific information about the item selected) gets pushed onto the nav stack. When I hit the back button on that controller, I observe a strange behavior: The section headers of the normal table view overdraw the section headers of my search results table view. They are displayed as if my normal table view is being displayed (I can see that from the number of rows between the headers, though the rows remain empty). The search result table rows are still being displayed.
This behavior comes from the fact that I reload the table view on viewWillAppear. I do this to react on changes in the database made by the user at some other point in the application or automatic background data updates. I already tried to poll if the recently displayed table view is being shown via
(self.tableView == self.searchDisplayController.searchResultsTableView)
but that statement is always false after I return to my normal table view controller.
The question: how can I poll the correct state of my table view to avoid the displaying errors?

The UISearchDisplayController class implements an active property. Guess what it's used for :-)
e.g. just check for (self.searchDisplayController.active) or ([self.searchDisplayController isActive]).

Related

Retain Cell Selection After View has Changed

I currently have a navigation controller in my project.
The user is presented with 3 tables, one at a time, within which they can select some options.
My issue is that if a user makes a mistake and wants to go back to the previous table, the option they chose is no longer selected. This causes them to select it again - which creates duplicates in an array that stores data.
How can I have the table retain the selection so that if the user goes back to the previous table the option remains selected?
Are you using UITableViewController for your tables?
From Apple's documentation:
In -viewWillAppear:, it reloads the table's data if it's empty.
Otherwise, it deselects all rows (with or without animation) if
clearsSelectionOnViewWillAppear is YES.
So probably you will need to just set clearsSelectionOnViewWillAppear to false on your view controllers and hopefully everything will work as expected.

in iPad tableview shows more records when navgigate back from another view inside a popover

I have a popover view which displays a table with two rows and the size of the popover is adjusted to show only those two rows. After i click any one of the rows i navigate forward to a new table view and the popover size increases accordingly. when i navigate back to the original table view having two rows the popover size increases by one row. It shows a three rows with a empty third row.
Please find my code below.
in initWithFrame for the table view i set the value for popover using contentsizeforviewinPopover. works fine when the view loads
After navigating back i am setting the same value(contentsizeforviewinPopover) inside viewwillAppear. But now the view has three rows.
Please suggest any solution.
I got it rectified. When the initial table view navigatesforward to the next table view i will set the value for contentsizeforviewinPopover to zero in viewdiddisappear. Again when in navigate back, the popover displays with proper size with the proper values present in viewwillappear.
I think there is some problem with you table datasource. As you said that popover size get changed and also there is an empty row in the table. I think your datasource get updated with blank data.
Please check your datasource in between your navigation.
Thanks

how to manage a stack of UITableViews without a navigation controller

I am new to iPhone development, and I am working on modifications to an existing iPhone app. The high-level overview of the issue is this.
I have a button displaying a pop-up containing a UITableView.
I'd like to click on a menu item and display a second UITableView with sub-items, including a back option. If the user clicks back, they go the original UITableView. If the sub-item has additional sub-items underneath it, it should (when clicked) launch another UITableView with these options. There is also a back button as a menu item that will allow the user to navigate to the previous menu displayed.
The challenge here is that I am not using a navigation controller. the original developer only wants to add UITable Views to the stack, add transitions between them as you go from one menu to the other. Most of the tutorials I have seen and tried utilize a navigation controller and Interface Builder to associate the UITableViews.
Right now, I have an XML data source populating the menu, and when I click on a menu item, the titles change correctly, but still uses the same UITableView to display the options - this has consequences of course, as some of the sub-items may not fit on a screen.
any thoughts on how this can be done? I can post some code if necessary, although I think the general description should be able to ring a bell with one of you smart guys!
This can be done in numerous ways.
I haven't done this first one, but you can probably create a UINavigationController and set its view to the appropriate frame (inside the bubble) hide the navigation bar and set the action of your back button to pop the current view controller.
Another method is to have multiple tableviews on one controller, the delegate and datasource methods have the UITableView as an argument so you can distinguish them when setting the height of your rows, headers etc and when returning a UITableViewCell.
The way I've chosen to deal with such configurations is to have one UITableView and have only the datasource change. When you reload, insert, delete rows or reload the whole table, you can change anything you want depending on the current datasource level. The easiest none animated way is to reload the whole table.
a) If your "options" go off-screen height wise (you want fixed height) table change the - (CGFloat)tableview:(UITableView *)table heightForRowAtSection:(NSInteger)section return value
b) If your "options" go off-screen length wise either make your cell's default textLabel flexible: cell.textLabel.adjustsFontSizeToFitWidth = YES; cell.textLabel.minimumFontSize = 14; or have custom cells (lookup subclassing UITableViewCell, which is recommended) for each datasource level.
If you subclass TableViewCells remember to have different dequeue cell identifiers for each level, so the table doesn't provide you with another level's cell class.
For the "stack" of tableviews or datasources, you can have an NSMutableArray with addObject for push and removeLastObject for pop.
For animations, UITableViews can animate their rows/sections for 3. (see documentation for insert, delete, reload - Rows/Sections UITableView class reference), for 2. you can even have UIView (if not CoreAnimation as Grimless suggested) animations, that move the current tableview to the left (setFrame:) and the next tableview from the right (setFrame offscreen before animation and then in place in the beginAnimation-commitAnimation clause), but make sure you add the tableviews in a container view (the bubble interior) that clips its subviews.
Oi. This is gonna be a tough one. My suggestion would be to maintain your own stack implementation. Then, use CoreAnimation to add/remove UITableViews from your main view controller to get animated effects. So whenever the user clicks on an element in the current table view, the appropriate controller creates a new controller and table view, and then your custom navigation controller pushes the old one onto the stack, removes the old table view from the main view, sets the new controller as the current one, and adds the new table view to the main view. Kinda messy, but I think it will work.

Adding UILabel on top of UITableView

I have an iPhone project with a NIB that only has a table view (UITableViewController). My delegate loads the nib (and associated controller) and all is well. Now I'd like to have UILabel show up when there is no data to show in the table view. Revisiting the NIB it occurred to me that only the File's Owner, Delegate, and the Table View are present (i.e. no Window).
It seems like I've seen this before in apps when say you search for something and there are no results. What is the best practices approach to adding the UI label or any other UI element for that matter.
Thanks!
You can just add a UILabel in interface builder over top of your table view and set it to hidden. Then, when you get 0 results, just call -setHidden:NO on the label.
You could as easily just return a single table row in the case where your results count is zero with some instructive text such as "No results" that is not tappable/selectable.

Is it possible to put a hidden search bar above a grouped table view?

In OS3.0 a lot of plain table views have an initially hidden search bar that can be accessed by scrolling down to reveal it (e.g. mail, ipod).
Is it possible to do the same thing for a grouped table view?
Background:
I'm using a grouped table view as a static navigation menu (similar to the Things app). The content never changes, it's just a way to choose which view to push next. Above the table view, I have a search bar. I'd like that search bar to be hidden initially, as it doesn't look good and may also be confusing for new users - also because that seems to be the standard now.
Note, the search bar has nothing to do with the datasource of the table view it's in - it's not searching the contents of that table view. It's a search on a remote server. The results are displayed in a new view which is pushed on the stack. The search bar is intended to be just a quick way to get at that functionality.
UITableView inherits from UIScrollView, so set the bounds of the UITableView to move the search bar out of view when the UITableView is about to start displaying.