I am working on a Navigation controller that will allow users to select from different media. I have a basic text-based controller working (top image), but am running into issues as I start to add detail to it (mock-up bottom image). The most pressing question which is, how should I store the data?
Things to keep in mind are:
List of albums will always be short (i.e. less than 10) and static
Display correct thumbnail image of album art in each row of Albums table
Same but larger image of album art in detail view of selected album
Text field that can hold a couple paragraphs of information in detail view of selected album
I've seen data stored in a number of ways:
Array within my AlbumsController.m file, plist file, Dictionary, SQL database
I like the array approach, as it is really convenient to implement, but doesn't seem to allow for:
different image in each row
second line of text (i.e. album date under album name in table row cell)
place to store a couple of paragraphs of text that will only be shown on the detail screen
I'd really like to be able to create a single AlbumsDetail.xib file as a template and just have the appropriate information populate the fields based on which album was selected from the Albums table.
Quote:
Current Goal
Thank you for any guidance. I have been through the Apple sample code (e.g. TheElements), a couple books, and the threads here. The approaches all have slightly different implications, and I'm having trouble reconciling them...
I guess the question I have for you is whether you want the user to be able to add, edit or change the data in any way?
If the answer is no: If you aren't gonna have too much data then you can just stick with the array approach. You can even hard code it.
Quote:
I like the array approach, as it is really convenient to implement, but doesn't seem to allow for:
* different image in each row
* second line of text (i.e. album date under album name in table row cell)
* place to store a couple of paragraphs of text that will only be shown on the detail screen
You can do this with arrays but not just one. To make it simple for your case you could just do three arrays that are all the same size. so:
Just make sure the first element in title_array is intended for details_array and image_array so that when you're setting up your cell for the table view you would set your title to: [title_array objectAtIndex:indexpath.row]; and your image to: [image_array objectAtIndex:indexpath.row];
Then in your details view you would pass in the details_array element at the same index.
Let me know if you have any other questions regarding that.
Otherwise if you do need to edit it I would suggest sql which is another animal.
In terms of your views and view controllers. If you only want to have one .xib then make a tableviewnavigationcontroller (or however its spelled) and added a details view to it. For the first two levels in your image you will need to build the tableview with the delegate methods. If this is all in one controller and using arrays you will have to have all of the array information hard coded in and you will have to keep track of what level you are in and what item has been selected(if you are in the second level). You can store this in the app delegate pretty easily.
Sorry if my reply is long. Let me know if there is something you need more clarification on.
I guess the question I have for you is whether you want the user to be able to add, edit or change the data in any way?
I don't need the user to do anything other than view the data that I provide.
I've made some decent progress thanks to your message, and a tutorial I found. I am a little stuck now, trying to get my albumYear label to display info from an array. The albumTitle label displays fine. The albumYear label will display the same value in all rows if I hard code it
Code:
albumYearValue.text = @"Sub Value";
When I use the following code to try to get the albumYear label to display a different value in each row based on data from an array, it's just blank.
To be honest I've yet to use dictionary stuff. If you can hard code what you want then the problem has to be in the data structure. If I were you I'd use the debugger at this point and step through the code to see if the array contains what you want and when you want it.
I am not set on using dictionary. Just an example I found that I was able to get working. If there is an easier way, please do share.
Quote:
Originally Posted by rooster117
If you can hard code what you want then the problem has to be in the data structure. If I were you I'd use the debugger at this point and step through the code to see if the array contains what you want and when you want it.
Could be something simple.
You are probably right. I spent a couple hours troubleshooting this evening, and can't seem to find it. Maybe a fresh look at it tomorrow will help.
For me I would just make a second array for the album year and keep them in synch. So each index of one corresponds to the same index of the other. Then you could just use the same "indexPath.row" to access them both. This probably breaks some coding standards but it would be easy to get working and you could always change methods once you get the basics down.
I personally find most of my problems like this with the inline debugger. Good luck.