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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-07-2011, 11:59 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 63
CanDev is on a distinguished road
Default Drill Down not working...need help

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
Code:
#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
Code:
- (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
Code:
@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
Code:
#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...
CanDev is offline   Reply With Quote
Old 10-08-2011, 01:00 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by CanDev View Post
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
Code:
#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
Code:
- (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
Code:
@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
Code:
#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

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 10-08-2011, 02:54 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 63
CanDev is on a distinguished road
Default

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.
CanDev is offline   Reply With Quote
Old 10-08-2011, 03:17 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by CanDev View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 10-08-2011 at 03:36 PM.
Duncan C is offline   Reply With Quote
Old 10-08-2011, 03:24 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 63
CanDev is on a distinguished road
Default

Quote:
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

Last edited by CanDev; 10-08-2011 at 03:27 PM.
CanDev is offline   Reply With Quote
Old 10-08-2011, 03:37 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by CanDev View Post
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

Check out our apps in the Apple App store


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.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 10-08-2011, 03:41 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 63
CanDev is on a distinguished road
Default

Quote:
Originally Posted by CanDev View Post
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.
CanDev is offline   Reply With Quote
Old 10-11-2011, 04:21 PM   #8 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 63
CanDev is on a distinguished road
Default Solved

Quote:
Originally Posted by CanDev View Post
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
CanDev is offline   Reply With Quote
Reply

Bookmarks

Tags
drill down table view, plist, table, table view tabbar, tableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 401
17 members and 384 guests
13dario13, 7twenty7, eski, EvilElf, glenn_sayers, HemiMG, jarv, LunarMoon, n00b, pbart, Pudding, QuantumDoja, sacha1996, Sami Gh, UMAD, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0