Hi, I have been trying to figure this out for days... If anyone could give me some guidance it would be greatly appreciated. I created a simple drill down similar to the simple drill down code on the apple site. <https://developer.apple.com/iphone/library/samplecode/SimpleDrillDown/index.html> Everything works perfect except now I am trying to have a UIButton on a new first view link to the drilled down view. I am not sure if this is even possible. Here is the code for the detail view controller that works from the table view.
So instead of the clicking the first row and getting the information you would click buttton 1 and get the information, and instead of second row and getting the informaion you would click button 2 and so on... I hope this makes sense. Thanks...
#import "DetailViewController.h"
@implementation DetailViewController
@synthesize detailItem;
- (void)viewWillAppear
BOOL)animated {
// Update the view with current data before it is displayed
[super viewWillAppear:animated];
// Scroll the table view to the top before it appears
[self.tableView reloadData];
[self.tableView setContentOffset:CGPointZero animated:NO];
self.title = [(NSDictionary *)detailItem objectForKey
"title"];
}
// Standard table view data source and delegate methods
- (NSInteger)numberOfSectionsInTableView
UITableView *)tableView {
// There are three sections, for characters, genre, and date, in that order
return 3;
}
- (NSInteger)tableView
UITableView *)tableView numberOfRowsInSection
NSInteger)section {
NSInteger rows = 0;
switch (section) {
case 0:
case 1:
// For genre and date there is just one row
rows = 1;
break;
case 2:
// For the characters section, there are as many rows as there are characters
rows = [[detailItem objectForKey
"mainCharacters"] count];
break;
default:
break;
}
return rows;
}
- (UITableViewCell *)tableView
UITableView *)tableView cellForRowAtIndexPath
NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"tvc";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Cache a date formatter to create a string representation of the date object
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat
"yyyy"];
}
// Set the text in the cell for the section/row
NSString *cellText = nil;
switch (indexPath.section) {
case 0:
cellText = [dateFormatter stringFromDate:[detailItem objectForKey
"date"]];
break;
case 1:
cellText = [detailItem objectForKey
"genre"];
break;
case 2:
cellText = [(NSArray *)[detailItem objectForKey
"mainCharacters"] objectAtIndex:indexPath.row];
break;
default:
break;
}
cell.text = cellText;
return cell;
}
/*
Provide section titles
HIG note: In this case, since the content of each section is obvious, there's probably no need to provide a title, but the code is useful for illustration.
*/
- (NSString *)tableView
UITableView *)tableView titleForHeaderInSection
NSInteger)section {
NSString *title = nil;
switch (section) {
case 0:
title = NSLocalizedString(@"Date", @"Date section title");
break;
case 1:
title = NSLocalizedString(@"Genre", @"Genre section title");
break;
case 2:
title = NSLocalizedString(@"Main Characters", @"Main Characters section title");
break;
default:
break;
}
return title;
}
@end
So instead of the clicking the first row and getting the information you would click buttton 1 and get the information, and instead of second row and getting the informaion you would click button 2 and so on... I hope this makes sense. Thanks...
#import "DetailViewController.h"
@implementation DetailViewController
@synthesize detailItem;
- (void)viewWillAppear
// Update the view with current data before it is displayed
[super viewWillAppear:animated];
// Scroll the table view to the top before it appears
[self.tableView reloadData];
[self.tableView setContentOffset:CGPointZero animated:NO];
self.title = [(NSDictionary *)detailItem objectForKey
}
// Standard table view data source and delegate methods
- (NSInteger)numberOfSectionsInTableView
// There are three sections, for characters, genre, and date, in that order
return 3;
}
- (NSInteger)tableView
NSInteger rows = 0;
switch (section) {
case 0:
case 1:
// For genre and date there is just one row
rows = 1;
break;
case 2:
// For the characters section, there are as many rows as there are characters
rows = [[detailItem objectForKey
break;
default:
break;
}
return rows;
}
- (UITableViewCell *)tableView
static NSString *CellIdentifier = @"tvc";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Cache a date formatter to create a string representation of the date object
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat
}
// Set the text in the cell for the section/row
NSString *cellText = nil;
switch (indexPath.section) {
case 0:
cellText = [dateFormatter stringFromDate:[detailItem objectForKey
break;
case 1:
cellText = [detailItem objectForKey
break;
case 2:
cellText = [(NSArray *)[detailItem objectForKey
break;
default:
break;
}
cell.text = cellText;
return cell;
}
/*
Provide section titles
HIG note: In this case, since the content of each section is obvious, there's probably no need to provide a title, but the code is useful for illustration.
*/
- (NSString *)tableView
NSString *title = nil;
switch (section) {
case 0:
title = NSLocalizedString(@"Date", @"Date section title");
break;
case 1:
title = NSLocalizedString(@"Genre", @"Genre section title");
break;
case 2:
title = NSLocalizedString(@"Main Characters", @"Main Characters section title");
break;
default:
break;
}
return title;
}
@end