Parse.com: PFQueryTableViewController with PFUser - iphone

I am using the Parse.com framework with my iOS app. I want to have two section in an UITableView. I read that I can use the PFQueryTableViewController to query data from the parse cloud and have it in a UITableView. How can I use PFQueryTableViewController to query the User class usernames to be in one section of the UITableView, and the friends of the currentUser to be in the other section of the UITableView, friends is an array variable that I made every PFUser have. How would I do this?

The PFQueryTableViewController class is really intended to be used for a single query only - your requirement needs two queries to be performed (one for the currentUsers's friends, and one for all User's usernames. If I were you I'd implement my own table view controller that performs the two queries in the background separately, and manages its own calls to reloadData when the data is returned from Parse for each section of the tableView.

Related

How to map UITableView cell to a remote database backend?

I'm making a simple To-Do list app for the iPhone with a rails backend.
So far, I can pull all the tasks in a To-Do list from the web app, parse the JSON, and insert it into the UITableView.
The json response from rails:
[
{"id":1,"name":"Buy bread"},
{"id":8,"name":"Get gas"},
{"id":14,"name":"Call John"}
]
In the UITableView, a row for each task, the textLabel of the cell is the name of the task:
The problem I'm having now is how to associate the cell with the record id of the task.
Two tasks can have the same name, so I can't just get the id from the hash based only on the name.
I need the record id, so I can post back to the rails app, after the user edits the UItableView (deletes a task for example).
Is there a property I can set on the cell? I feel like I'm missing something obvious. This is my first iPhone app, so please be gentle, hehe.
How are you getting the JSON array to an Objective-C array for use in the table? You'll have to do that again for the ID of the task, and in your - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method use something like theID = [idArray objectAtIndex:indexPath.row];
The better solution would be to maintain a proper data model on the client. You could use the JSON as your model, but Core Data is a bit more robust. What you'd want is to have your controller associate what it knows about the view with what it knows about the model. For instance, if you use didSelectRowAtIndexPath: You'd want to use this index path to map to your model.
Your solution of setting a property on a cell which allows a client of your view to query your data model is in violation of the rules of the MVC paradigm. It couples your view to your model which isn't great.

How to store information in a detailed view from a TableView

I have a bunch of information from a few views (stored in a singleton) that I collected from the user, now all displayed in one confirmation view. How do I take this information and create a new UITableViewCell that one can click on to see the entered information.
And, although this comes later, how do I make sure this data is stored between sessions and never deleted unless done so by the user.
Thanks for the help.
Showing the data in a UITableView is quite trivial, and I suggest you check out the UITableView Class Reference, UITableViewDelegate and UITableViewDataSource protocols to find out how you can do that.
For the storage of the data, one of the ways to do so is by using the NSUserDefaults.
Once you have stored the user's data, you can access the NSUserDefaults from a different view without having to pass any objects between those views / controllers.
Generally you'll want to use properties and delegates to pass data between views.
As far as persisting data, for light-weight data (like preferences) use NSUserDefaults. For more complex data, use Core Data.

iPhone - pull data directly from a database to tableview cells?

I currently have an application with a tableview, I've followed the basic tutorials and use an NSArray and NSDictionary that I populate myself and use this to populate the cells in the tableview.
I have also been able to create a test database and I can pull the information from here into an array and again add this array to an NSDictionary and populate the data in the cells of the tableview.
However it doesn't make sense to me that I have to copy the data from my database into memory (array) and then use this to populate the cells, is there a way to populate the cells of a tableview without needing to use an Array and dictionary and instead access the info for each cell directly from the database?
Or is pulling data from the database into memory and using it from there the recommended way?
Take a look at the Core Data Programming Guide. Core Data uses so-called "faults", that aren't fired until you access them. Additionally, Apple provides a NSFetchedResultsController to manage a UITableView with a Core Data-based database.

Json - iPhone app: uitableview and uiwebview

I am quite new to Xcode and Json.
In my app, I have navigation through pages via tableviews (drill down). What I want to do now, is to use Json to create my tableviews and then when I select a cell in the uitableview, it will go to a website through the next page via a uiwebview.
How will I do this?
Parse your json using a parser
Create the parsed response as a data model for table view. You can use a Dictionary/array to keep things simple
Implement the tableview delegate methods and get the selected index
On didselectatrowindex method you create a new view, fetch the url from your model and load it into the webview.
I could write some code but thats really too much you are asking for. If you get stuck in any of the steps above, do leave a comment. I will be glad to help you out.

Using CoreData outside of a TableView on the iPhone

My application has a simple data model with 70 read-only records grouped into six categories. Currently the persistent data is stored in an XML file which I parse on application launch, and create objects for each record which are stored in an NSMutableArray.
I then populate a UIPickerView from the objects stored in the array, and when the user selects a row in the picker, display content pulled from the same objects.
Using CoreData and SQLite would use much less code, but it seems to be designed to work with UITableViews exclusively.
Has anyone used CoreData to fetch records outside of the UITableView interface?
Thanks
jk
Core Data is not designed to work with UITableViews only. Although it's really easy to Core Data with the NSFetchedResultsController to populate a table view you can still do all the fetches you want on your an.
Just make your own NSFetchRequests to get the data you want. From the list of objects, particular objects or just single values you can use this date for whatever purpose intended.
I put my custom Core Data methods into the application delegate, where they can be called from any class. To do this, I add a #define as follows:
#define UIAppDelegate ((MyAppDelegate *) [[UIApplication sharedApplication] delegate])
I can then call my methods like so:
[UIAppDelegate fetchBooks:managedObjectContext];
A UITableView is not required for any of this.