Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-03-2009, 02:33 PM   #1 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Question Navigation Controller Data Store Choice

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
Here's what I use now:
Code:
- (void)viewDidLoad {
	NSArray *array = [[NSArray alloc] initWithObjects:@"Album 1", @"Album 2", @"Album 3", nil];
	self.list = array;
	[array release];
	[super viewDidLoad];
}
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...

Last edited by DenVog; 05-03-2009 at 03:06 PM.
DenVog is offline   Reply With Quote
Old 05-04-2009, 06:46 PM   #2 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: California
Posts: 54
Default first response

Hello,

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:

NSArray *title_array = .....
NSArray *details_array = .....
NSArray *image_array = .....

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.

Thanks
-Ryan

Bolt and Nut iphone utility app
Tooth Brush Timer
rooster117 is offline   Reply With Quote
Old 05-09-2009, 11:07 PM   #3 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Default

Hi Ryan. Thanks for your detailed reply.

Quote:
Originally Posted by rooster117 View Post
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.

Code:
- (void)viewDidLoad {
	 [super viewDidLoad];
	 
	 //Initialize the array
	 albumsArray = [[NSMutableArray alloc] init];
	 
	 NSArray *albumTitleArray = [NSArray arrayWithObjects:@"Album 1", @"Album 2", @"Album 3", nil];
	 NSDictionary *albumTitleDic = [NSDictionary dictionaryWithObject:albumTitleArray forKey:@"Title"];
	 
	 NSArray *albumYearArray = [NSArray arrayWithObjects:@"1995", @"2000", @"2005", nil];
	 NSDictionary *albumYearDic = [NSDictionary dictionaryWithObject:albumYearArray forKey:@"Year"];
	 
	 [albumsArray addObject:albumTitleDic];
	 [albumsArray addObject:albumYearDic];

	 copyListOfItems = [[NSMutableArray alloc] init];
	 
} 

#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	//Number of rows it should expect should be based on the section
	NSDictionary *dictionary = [albumsArray objectAtIndex:section];
	NSArray *array = [dictionary objectForKey:@"Title"];
	return [array count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
	
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil)
		cell = [self getCellContentView:CellIdentifier];
	UILabel *albumTitleValue = (UILabel *)[cell viewWithTag:kAlbumTitleValueTag];
	UILabel *albumYearValue = (UILabel *)[cell viewWithTag:kAlbumYearValueTag];

	NSDictionary *dictionary = [albumsArray objectAtIndex:indexPath.section];
	
	NSArray *titleArray = [dictionary objectForKey:@"Title"];
	NSString *titleValue = [titleArray objectAtIndex:indexPath.row];
	albumTitleValue.text = titleValue;
	[titleValue release];

	NSArray *yearArray = [dictionary objectForKey:@"Year"];
	NSString *yearValue = [yearArray objectAtIndex:indexPath.row];
	albumYearValue.text = yearValue;
	[yearValue release];
	return cell;
}

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
	
	CGRect cellFrame = CGRectMake(0, 0, 300, 65);
	CGRect albumTitleValueRect = CGRectMake(80, 5, 200, 15);
	CGRect albumYearValueRect = CGRectMake(80, 25, 200, 15);
	UILabel *titleTemp;
	UILabel *yearTemp;
	UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:cellIdentifier] autorelease];
	
	
	//Initialize Label with AlbumTitle Tag
	titleTemp = [[UILabel alloc] initWithFrame:albumTitleValueRect];
	titleTemp.tag = kAlbumTitleValueTag;
	[cell.contentView addSubview:titleTemp];
	[titleTemp release];
	
	//Initialize Label with AblumYear Tag
	yearTemp = [[UILabel alloc] initWithFrame:albumYearValueRect];
	yearTemp.tag = kAlbumYearValueTag;
	yearTemp.font = [UIFont boldSystemFontOfSize:12];
	yearTemp.textColor = [UIColor lightGrayColor];
	[cell.contentView addSubview:yearTemp];
	[yearTemp release];
	
	return cell;
}
Thanks again for your assistance.
DenVog is offline   Reply With Quote
Old 05-09-2009, 11:58 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: California
Posts: 54
Default well

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.

Could be something simple.

Sorry if this response isn't as helpful

-Ryan
rooster117 is offline   Reply With Quote
Old 05-10-2009, 12:10 AM   #5 (permalink)
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 622
Default

Quote:
Originally Posted by rooster117 View Post
To be honest I've yet to use dictionary stuff
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 View Post
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.
DenVog is offline   Reply With Quote
Old 05-10-2009, 12:36 AM   #6 (permalink)
Registered Member
 
Join Date: Mar 2009
Location: California
Posts: 54
Default What I would do

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.

-Ryan
rooster117 is offline   Reply With Quote
Reply

Bookmarks

Tags
navigation controller, navigationcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 237
16 members and 221 guests
ADY, Alsahir, cacao, dacapo, Dani77, Desert Diva, djohnson, F_Bryant, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:53 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0