Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Drill Down not working...need help

CanDevCanDev Posts: 63Registered Users
edited October 2011 in iPhone SDK Development
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 <UIKit/UIKit.h>

@interface DrillDownTrialAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    
    NSDictionary *data;

}
@property (nonatomic, retain) NSDictionary *data;

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end
appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // Add the tab bar controller's current view as a subview of the window
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Bands" ofType:@"plist"];
    NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path];
    self.data = tempDict;
    [tempDict release];
    
    
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
tableview.h
@interface TableViewController : UITableViewController {
    
    NSArray *bandData;
    NSString *CurrentTitle;
    NSInteger CurrentLevel;
}

@property (nonatomic, retain) NSArray *bandData;
@property (nonatomic, retain) NSString *CurrentTitle;
@property (nonatomic, readwrite) NSInteger CurrentLevel;

@end
tableview.m
#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...
Post edited by CanDev on

Replies

  • Duncan CDuncan C Posts: 9,034Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited October 2011
    CanDev wrote: »
    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 <UIKit/UIKit.h>
    
    @interface DrillDownTrialAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
        
        NSDictionary *data;
    
    }
    @property (nonatomic, retain) NSDictionary *data;
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    
    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    
    @end
    
    appdelegate.m
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        // Add the tab bar controller's current view as a subview of the window
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Bands" ofType:@"plist"];
        NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path];
        self.data = tempDict;
        [tempDict release];
        
        
        self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    tableview.h
    @interface TableViewController : UITableViewController {
        
        NSArray *bandData;
        NSString *CurrentTitle;
        NSInteger CurrentLevel;
    }
    
    @property (nonatomic, retain) NSArray *bandData;
    @property (nonatomic, retain) NSString *CurrentTitle;
    @property (nonatomic, readwrite) NSInteger CurrentLevel;
    
    @end
    
    tableview.m
    #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.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • CanDevCanDev Posts: 63Registered Users
    edited October 2011
    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.
  • Duncan CDuncan C Posts: 9,034Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited October 2011
    CanDev wrote: »
    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
    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:

    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.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • CanDevCanDev Posts: 63Registered Users
    edited October 2011
    Try this. Add the following statement at the very beginning of your didSelectRowAtIndexPath: method:

    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
  • Duncan CDuncan C Posts: 9,034Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited October 2011
    CanDev wrote: »
    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.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • CanDevCanDev Posts: 63Registered Users
    edited October 2011
    CanDev wrote: »
    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:]

    which would be correct place to go.
  • CanDevCanDev Posts: 63Registered Users
    edited October 2011
    CanDev wrote: »
    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.

    Live and Learn

    Thanks for the help Duncan
Sign In or Register to comment.