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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 05-09-2009, 10:07 PM   #3 (permalink)
DenVog
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 624
DenVog is on a distinguished road
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
 

» Advertisements
» Stats
Members: 175,637
Threads: 94,101
Posts: 402,822
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jessicagx69
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:28 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.