How to get Rows updated automatically? - iphone

HI all,
I have made my custom Data Model, custom Data Source and a TTTableViewController which uses my data source, now in data model there we are mentaining the array, if something changes in the datamodel, ui should auto reflect those change, how this thing can be implemented?

You can send the -reloadData message to the UITableView. Also, there are methods in UITableView to insert/delete particular rows. This also can give you nice animations. Please take a look at the "Table view programming guide" for details.

Related

What is the three20 method of passing objects between view controllers?

I have a basic RSS Reader I made from three20 tutorials using TTLauncherView as a menu to different feeds and TTTableViewController to show the feed list.
However, I am stuck at the point where from the feed list I click to view the feed item details. I use TTTableImageItem to display my feed items and I'm clueless as to how I am to use the URL variable in said TTTableImageItem to pass objects to the view controller showing the feed item.
I did some searching and I am lead to think that this cannot be done except via TTURLRequest, which leaves me even more confused.
Most of my code is adapted from IOSGuys tutorial, which uses a custom data source, data model and parser. I have tried making the data source and data model a singleton but to no avail and I'm unsure if that's even the best way to proceed for something as (presumably) simple as this.
Ideally I intend to pass the entire array of feed items with another argument for the index so that I can make use of UIPageControl to swipe between feeds when I'm at a more in-depth view.
Much help is appreciated! I have been spending too long looming around already!
The usual way of doing this is to have some sort of global singleton Data Manager class that manages the data models through Core Data, In-Memory Stores or other ways. Each model would have some sort of unique identifier. Doing it this way lends itself to a URL only stack needed to recover your navigation history without having to write state out to file in order to restore. You also can bring up any page in the app at any place with only a single URL. Using a URL scheme only then becomes trivial as you can do something like:
yourapp://blogs/jd82kd9
and have the blog view controller's init method contact the Data Manager for the blog with the unique identifier of jd82kd9
In your navigator's mappings, you would have something like this:
[map from:#"yourapp://blogs/(initWithBlogID:)") toViewController:[MyBlogViewController class]];
and then the initWithBlogID method would have the signature:
- (id)initWithBlogID:(NSString *)blogID;
see also Three20 : how to pass a class of objects between 2 views

Any code examples for using a UITableView to implement in-app settings?

Any code examples for using a UITableView to implement in-app settings?
That is where to get the iPhone settings app look and feel one custom builds the settings into a UITableView. So you you would custom set the sections and cells that get returned with switch type statements.
In particular interested in reviewing the coding approach for how to:
best configure the cellForRowAtIndexPath and didSelectRowAtIndexPath
how to handle those cells for which you want in cell editing (e.g. text)
those cells where you need to launch off into another screen to set a date/time for example
how to collect up parameters and pass back to calling rootViewController (in my case need to persist data out to Core Data persistence)
Note: using Core Data so not interested in using libraries such as InAppSettings [any feedback re whether such libraries might be ok appreciated at this SO question I created].
thanks
I am not sure if you can use the inappsettingskit for your needs. It is open source so you are free to modify the code as you wish, but it doesn't look as an out of the box solution.
If you want to make these settings available in the settings app you will have to live with some workarounds for example saving NSDate AND getting a nice UI control to modify it: Use a textfield, there is no control specified which let's you pick a date. Have a look at Apple's documentation.
So the last option will be coding. First of all, determine what kind of types you want to support. Then create custom TableViewCells which reflect those kinds. If some kinds do need some special way of editing, for example a color picker, you'll have to write those controllers as well. You set a cell into editing mode with the delegate method tableView:didSelectRowAtIndexPath and present the custom controller or get into editing directly for example a UITextField. A Slider is handled directly without any coding.
The cells will need some kind of identifier so you can identify those in your model. A TableView and Core Data can interact with each other pretty well by using the NSFetchedResultsController. Create a simple window based app with a template and check the Use Core Data for Storage. The rootViewController illustrates how a tableView works together with Core Data. For your case it will be getting a bit more complicated as inserting a row will have to determine what kind of cell it should add.
I think you should look into this and get back with some more specific questions.

Three20 + Core Data Simple Example

I've combed through SO, the Google group, and the blog-o-sphere trying to find an example of how to get the Three20 library to work with Core Data, and have not found much to speak of.
Does anyone here know where I could find a simple tutorial (or be willing to post one) on how to work with Core Data entities and Three20? Maybe something like:
I have an Core Data entity called Book which has the String attributes title and description. How would I create a simple app that would open with a table view showing a listing of all books, and when a row is touched push a view onto the nav controller that displays the selected book object's attributes? (just an idea -- anything that shows how to work with Core Data / Three20 would be much appreciated)
Thanks!
Core Data and Three20 won't have any specific implementation. They are tools that you can use to achieve the specific implementation yourself. You use Three20 to display the data you have in Core Data.
I suggest you dump Three20 and learn the basics of programming a standard table view controller first. You can see the very basics of a Core Data driven table view controller by simply creating a new iPhone app in Xcode and selecting "Use Core Data for storage".
The template code will point you in the right direction at least and should help you grok MVC a bit better which will help you with a Three20 implementation. Meanwhile, you should also look into using mogenerator+xmo'd. It's the only way to fly when it comes to creating custom managed objects.
When in doubt, consult the master and ask specific Core Data questions here on SO.
As far as I know (Three20 documentation is sparse), there is no automatic way for Three20 to work with Core Data.
What I typically do is:
get the set of entities from Core Data
load the relevant data (from the entities) onto a TTTableViewDataSource (e.g. TTSectionedDataSource) in a TTTableViewController
voila!
There is probably a more dynamic way to do this by implementing a TTTableViewDataSource subclass and letting it collect/manage the entities, but I don't think it's worth the effort.
(Prior to loading your entities onto your datasource in Three20, you need to convert them into table items, because a datasource is not exactly a datasource in Three20).
e.g.
[TTSectionedDataSource dataSourceWithObjects:
#"", // section header
[TTTableTextItem itemWithText:#"An item" URL:#"http://www.facebook.com"],
[TTTableSummaryItem itemWithText:#"Another item"],
nil];
Update: I don't think that you can pass your entities directly to a detail view through a Three20 URL scheme (though there is a generic object mechanism). You can pass your object as part of an NSDictionary through the query parameter.
e.g. You can have a mapping such as
[map from:#"example://bookDetails/(initWithName:)" toViewController:[BookDetailsController class]];
and a method definition like this
- (id) initWithName:(NSString *)theName query:(NSDictionary *)query
You can use this to push the detail view controller
// navigationURLString = #"example://bookDatails/Alice in WonderLand" (in URL encoding)
[self.navigationController pushViewController:[[TTNavigator navigator]
viewControllerForURL:navigationURLString query:dictionaryWithEntity] animated:YES];
Alternatively, you can pass the pertinent data through as arguments in the init call or just the entity's primary key and fetch the object again inside the detail view controller.
There is now a branch of three20 - CoreDataSupport - that supports using a NSFetchedResultsController. There you will find a NSFetchedResultsDataSource.

Data driven UITableViewController implementations?

I have a UITableViewController which is starting to get a bit crazy with all the switch statements for each UITableView delegate.
Does anyone have any suggestions or examples of more of a data driven implementation for a UITableViewController? I'm thinking some type of data structure which would hold references of where to go to get cells for certain section/rows, where to get the section names, etc.
I think the More iPhone Development book describes something like this, just wanted to poll the community and see if anyone had some lessons learned on their own implementation.
I don't think there is a standard one that is generally suitable for everyone, but it's not too hard to whip up your own to suit the needs of your application. Basically, you want an array/list of sections, and for each section, an array/list of items. For each item, you'll want to allow specification of an image, text, detail text, and some sort of action to be fired upon selection.
If you want to get fancy, you can specify background colors, fonts, and other such things for each section heading, section footer, and item.
If your list items don't all look the same, then your tableView:cellForIndex: implementation needs to be smart enough to use different reuse identifiers for different-looking items.
A nice thing about this approach is that you can often use the same view and same controller for many "screens".
Consider using Core Data and NSFetchedResultsController.
Core Data's NSFetchedResultsController will do most of the data work for you. It might be overkill if your model is simple or not persisted though.

save checked items in table view for later reuse in iPhone

Got a conceptual question: If I got a tableview with about 100 items and the user can check as many as he wants from that list, how and where do I save the checked status of each individual item for later reuse?
In your own internal structures. UITableView isn't a database. It merely is an interface to your data. Any selection, deletion, addition, etc. will have to be handled by your code and stored. Typically you have some sort of a database or structure associated with the UITableView elements. When you get a check action, you can update a variable in that structure.
For an example of an SQL database backed UITableView app, see here.
For storing the checked elements of tableview, you have to maintain your code in didselectRow mthos of tableview. So, whenever you check the tableview row you can save it in an array. And save that array in the "NSUSerDefaul". So, that whenever you close the application, you can get back your selected tableview row array from "NSUserDefault". Or you can use sqlite database but it is better to use NSUserDefault as there is simple thing to do.
Please give your response if you find any problem.
You can use NSUSerDefault in your application from the following link: click here