Hi Ryan. Thanks for your detailed reply.
Quote:
Originally Posted by rooster117
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.