.xib with multiple UITableView or multiple lists in UIPopoverController - iphone

So I need to create a filter that is presented from a UIPopoverController. The different lists to filter on go to the data manager (model) class and query the sqlite database. The problem I am having conceptualizing is how to do this for multiple UIPopoverControllers with the most reusability. What I mean by that is, if I have two filters, one for say fruits, and another for say vegetables. Each one needs to be presented in a popover.
What I have done is, I have a UITableView that has a generic array. In the class that presents the popover, depending on what filter was pressed, I present the popover with the UITableView and the corresponding fruit and vegetable list.
The tricky part for me is, the problems with the checkmarks. Since my list consists of "All", plus each entry like "Apple" or "Orange", when the user selects All, no other checkmarks are visible. If the user selects apple, then all is deselected, and apple is selected with a checkmark. If apple is selected again, then apple is deselcted, and All is reselected. The way I handle this is, in didSelectrowForIndexPath, I query the model class, get my NSDictionary of YES/NO values for each key, and set it. This also takes care of when the popover is closed, and then presented again, then the checkmarks are all there in the last state they were in since the model was already updated.
So my two questions are
(1) if this implementation is 'ok,' then how would I have a separate list for each UITableView? It seems like since the UITableView manages one list, I would need to create multiple UITableViews, one for each filter, so those specific calls to the data manager, like "All", don't mess up the other filters
(2) is there a better way to do this? I'm open to suggestions! Thanks!

You may want to reconsider the user interface. It may not be necessary to have "All" as an option, and it may even be preferable to leave it out.
I've checked out how such filters work in other apps, and I've found that "All" is often not an option. When the table first appears, all fruits, say, are shown by default. When one entry, say "Apple", is selected, only apples are shown. When "Apple" is deselected, all results are shown once again.
This, of course, is the inverse of what is logical. Logically, if nothing is selected, nothing should be shown. However, I've found that when you're using such a filter without the "All" option, you don't realize the logical inconsistency and it somehow works very smoothly, as you would expect it to. On the other hand, it may appear more cumbersome for the user experience to have "All" being checked and unchecked automatically when the user is selecting an entirely different entry.
I've implemented a filter in just this way. In my opinion, it's more user friendly even if it's less logical.
As to the implementation, I just subclassed UITableViewController and set an array property for the filter entries. Then I re-use my subclass for different filters.

Related

How can I change a ViewController list (by changing predicate) without popping and pushing?

I have a ViewController whose view results from data from a fetch request with Predicate 1. I'd like to repeat the fetch request with a more restrictive Predicate 2 that will give a SUBSET of the data using Predicate 1.
Then I'd like to update (and possibly animate) that view on the iPhone screen by pressing a toggle button, so that the old and new views expand and collapse the rows. (I don't want to do this modally, as I'd like the user to see which rows came from the old rows.)
I'm thinking of something like the Phone application on the iPhone. Under the "Recents" tab, you'll see "All" and "Missed" buttons. When you press these buttons, it switches between showing all calls and just the missed ones by expanding/collapsing the rows. As far as I can tell, this is not a modal transition.
Can someone give me pointers as to how to do this?
If your view is a UITableView, you can use a combination of
-deleteRowsAtIndexPaths:withRowAnimation:
and
-deleteSections:withRowAnimation:
as well as the corresponding -insert methods, if applicable. You can batch multiple changes (so they animate at the same time) with -beginUpdates and -endUpdates.
I'm not aware of any way you'll be able to do this that doesn't involve iterating over one of the two sets and repeatedly calling -indexForObject on the other, though.
I found a way to expand/collapse rows by changing the heights of each cell, using tableView:heightForRowsAtIndexPath:indexPath:, as in:
http://www.alexandre-gomes.com/?p=482
Hope that's helpful to someone!

UITableView not working. Why?

I have a UITableViewController and I have specified the index titles so that the user can skip to specific letters much like the iPod app (the song list, specifically) on an iPhone. I have set up everything and implemented all the methods in the UITableViewProtocol.
Now, here is the problem. When I click an index on the right side (they are letters), the Table does not update properly. The top of it does update with the title I click on, but the actual rows do not. Why would this be happening? What method would I need to check? I find it weird that the title changes by the row content stays the same.
Thanks!
Are you setting up your dataSource as a two dimensional array? The indexes on the right will sort by the outside index.
Check out Apple's explanation on how to populate an indexed table. If you follow their code sample you should be able to get it to work.
http://developer.apple.com/iphone/library/documentation/userexperience/conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html

Can I implement something similar to iOS "Folders"?

I am going to make something that very visually similar to iOS4 folders but it's not folders at all )))
For example, I have 4 labels on screen - see sketch. Screen splits, if user click on label. Other lebels going down and we can see some text between splited views. If user click once more - view back to "normal" state as before. And so on.
Questions are:
is it confront iPhone HIG and app can be rejected?
what is the easiest way to implement this?
thanks )
alt text http://a.imageshack.us/img196/1306/sketch1.gif
Your App can always be rejected, for no reason at all.
This seems less like folders and more like an outline with collapsable items (or code folding in a programming editor). Plenty of outliner like apps in the store so no reason you should be able to do this (but read the first line of this answer again! No promises!).
Lots of ways to implement this. Here's a random quick one: If you use a UITableView and then have a UITableViewDataSource implementing class that has items marked as hidden/vislble. Then your numberOfRowsInSection method could return only the number of visible rows and the tableView:cellForRowAtIndexPath: would have to skip hidden rows (this might be too slow if you have many items - if so, cache visible count, use secondary array of indexes (or NSMutableIndexSet) of visible items, etc).

Managing multiple views and interactions

I have a table that contains 4 varying types of data and depending on the type of data that is selected by the user, a specific edit view is shown. One of these views has one edit field, a second one has 2 edit fields, a third one uses a picker, and so on. What's the best way to handle these varying views without an explosion of classes and without too 'switch'ing to figure out which data I'm working with?
One way I can think of is to have 4 different view controllers with respective views and then launch each one when the specific item is selected in the table but is there another elegant way to do this?
You can either go with the four different view controllers, or have one view controller that accepts an argument in the initialization for which content to create. The second approach seems to work better when the views are very similar (different numbers of the same controls, etc.)
For your case, some views have pickers, some have text fields... It seems that it might be best just to create a different view controller for each. With this you get added flexibility down the road, even though there is slightly more code to maintain.

How do I create a dictionary-style scroll bar for iPhone (like in the Contacts list)?

I am creating an iPhone app which I would like to have a similar interface to the iPhone's native contact picker view, i.e. an alphabetical list which you can scroll through, with a search bar up top which narrows down the list. Particularly, I'd like to be able to show the letters of the alphabet down the side so that as you scroll through the list, you see your position in the alphabet in the scrollbar. The problem is that my data basically consists of key-value pairs, not contact data, so I can't easily use the native contact picker.
As far as I can see, I have two options to achieve what I want:
Use the ABPeoplePickerNavigationController class and hack it to use an address book which I fill myself with non-address type data. The problem with this is that, by default, the address book will fill up with the contacts from the iPhone so that each time the app opened, I'd have to flush those contacts and build my own list. (Not to mention other problems associated with using an interface which is bound to a particular data structure)
Use a UISearchBar and UIScrollView. This would be fine, but I'm not sure how to do anything to the scroll bar except change its colour - I can't see how to override its contents.
Any advice on which is the simplest way? What are the pitfalls (particularly of 1)?
To get the letters down the side, you can just provide a -sectionIndexTitlesForTableView: method in your table view datasource. As for searching, there's a bit more work there, and it's very dependent on your data. A UISearchBar is the place to start, however.
For a search bar, have a look at TTSearchBar in the Three20 library.
Everything else can be easily implemented using UITableView.