Looking for a fresh set of eyes on this. I have followed the tutorial and placed a plist in 3 different apps. I can get the table to show up with the correct initial rows but nothing happens when I select a row. I followed this tutorial : UITableView ? Drill down table view tutorial | iPhone SDK Articles
Here is my code:
appdelegate.h
#import "TableViewController.h"
#import "DrillDownTrialAppDelegate.h"
#import "TableDetailView.h"
@implementation TableViewController
@synthesize bandData, CurrentLevel, CurrentTitle;
- (void)viewDidLoad
{
[super viewDidLoad];
if (CurrentLevel == 0) {
NSArray *tempArray = [[NSArray alloc] init];
self.bandData = tempArray;
[tempArray release];
DrillDownTrialAppDelegate *appDelegate = (DrillDownTrialAppDelegate *)[[UIApplication sharedApplication] delegate];
self.bandData = [appDelegate.data objectForKey:@"Rows"];
self.navigationItem.title = @"Competing Bands";
} else {
self.navigationItem.title = CurrentTitle;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.bandData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSDictionary *dictionary = [self.bandData objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:@"Title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.bandData objectAtIndex:indexPath.row];
//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];
if([Children count] == 0) {
TableDetailView *dvController = [[TableDetailView alloc] initWithNibName:@"TableDetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
else {
//Prepare to tableview.
TableViewController *rvController = [[TableViewController alloc] initWithNibName:@"TableView" bundle:[NSBundle mainBundle]];
//Increment the Current View
rvController.CurrentLevel += 1;
//Set the title;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];
//Push the new table view on the stack
[self.navigationController pushViewController:rvController animated:YES];
rvController.bandData = Children;
[rvController release];
}
}
@end
any thoughts would be appreciated. Been stuck for days and have tried a few times. Or if there is a better way without going through appdelegate and doing it all in tableview file...
Looking for a fresh set of eyes on this. I have followed the tutorial and placed a plist in 3 different apps. I can get the table to show up with the correct initial rows but nothing happens when I select a row. I followed this tutorial : UITableView ? Drill down table view tutorial | iPhone SDK Articles
Here is my code:
appdelegate.h
#import "TableViewController.h"
#import "DrillDownTrialAppDelegate.h"
#import "TableDetailView.h"
@implementation TableViewController
@synthesize bandData, CurrentLevel, CurrentTitle;
- (void)viewDidLoad
{
[super viewDidLoad];
if (CurrentLevel == 0) {
NSArray *tempArray = [[NSArray alloc] init];
self.bandData = tempArray;
[tempArray release];
DrillDownTrialAppDelegate *appDelegate = (DrillDownTrialAppDelegate *)[[UIApplication sharedApplication] delegate];
self.bandData = [appDelegate.data objectForKey:@"Rows"];
self.navigationItem.title = @"Competing Bands";
} else {
self.navigationItem.title = CurrentTitle;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.bandData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSDictionary *dictionary = [self.bandData objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:@"Title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.bandData objectAtIndex:indexPath.row];
//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];
if([Children count] == 0) {
TableDetailView *dvController = [[TableDetailView alloc] initWithNibName:@"TableDetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
else {
//Prepare to tableview.
TableViewController *rvController = [[TableViewController alloc] initWithNibName:@"TableView" bundle:[NSBundle mainBundle]];
//Increment the Current View
rvController.CurrentLevel += 1;
//Set the title;
rvController.CurrentTitle = [dictionary objectForKey:@"Title"];
//Push the new table view on the stack
[self.navigationController pushViewController:rvController animated:YES];
rvController.bandData = Children;
[rvController release];
}
}
@end
any thoughts would be appreciated. Been stuck for days and have tried a few times. Or if there is a better way without going through appdelegate and doing it all in tableview file...
Make sure your table view's allowsSelection property is true.
Then either set a breakpoint or add a log statement in your didSelectRowAtIndexPath method to make sure that method is getting called.
I'd recommend setting a breakpoint, and then single-stepping through the code to see what happens.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
well all the breakpoints I set are coming up in the bottom log as resolved. no matter where i put them and allow selection = true, not sure how to set that, but in my IB attributes for tableview, all of the appropriate boxes are selected.
well all the breakpoints I set are coming up in the bottom log as resolved.
Ok, that doesn't mean much. That just means that the compiler was able to figure out how to set the requested breakpoints
Quote:
no matter where i put them and allow selection = true, not sure how to set that, but in my IB attributes for tableview, all of the appropriate boxes are selected.
Huh? I have no idea what that means.
Try this. Add the following statement at the very beginning of your didSelectRowAtIndexPath: method:
Code:
NSLog(@"Entering %s", __PRETTY_FUNCTION__);
Then, when you run your program and tap one of the cells in your table view, do you see an entry in the log about entering didSelectRowAtIndexPath:
If not, you probably are not setting up your view controller to be the delegate of the table view. You can connect the delegate and dataSource links in interface builder (IB) assuming you created your able view in IB and not through code.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Try this. Add the following statement at the very beginning of your didSelectRowAtIndexPath: method:
Code:
NSLog(@"Entering %s", __PRETTY_FUNCTION);
Then, when you run your program and tap one of the cells in your table view, do you see an entry in the log about entering didSelectRowAtIndexPath:
If not, you probably are not setting up your view controller to be the delegate of the table view. You can connect the delegate and dataSource links in interface builder (IB) assuming you created your able view in IB and not through code.
ok dumb question ... What is _PRETTY_FUNCTION . I have seen it in a few posts. And Yes i have connected the datasource and delegate through the IB
ok dumb question ... What is _PRETTY_FUNCTION . I have seen it in a few posts. And Yes i have connected the datasource and delegate through the IB
I messed up in my post. It should be "__PRETTY_FUNCTION__", with double underlines at the beginning and the end.
It's a macro that the compiler replaces with a C string that represents the object and method that's called. It's very useful for logging information about your code as it executes.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
ok dumb question ... What is _PRETTY_FUNCTION . I have seen it in a few posts. And Yes i have connected the datasource and delegate through the IB
nevermind, looked it up and you had a spelling error, forgot the _ at end of FUNCTION. Anyway it logs 2011-10-08 14:37:27.585 DrillDownTrial[26910:207] Entering -[TableViewController tableView:didSelectRowAtIndexPath:]
nevermind, looked it up and you had a spelling error, forgot the _ at end of FUNCTION. Anyway it logs 2011-10-08 14:37:27.585 DrillDownTrial[26910:207] Entering -[TableViewController tableView:didSelectRowAtIndexPath:]
which would be correct place to go.
I forgot to add the nav controller. So I just added one above my tableview controller in the proper tab in the IB. Now everything works as expected.