"nextPath" is an instance variable in OrderEntryAppDelegate. It's value in the start method in OrderEntryAppDelegate.m is "/Subjects". However, when it's used in SubjectsController.m, it's value is nil. Why? What did I do wrong please?
Code:
[B]OrderEntryAppDelegate.h[/B]
#import <UIKit/UIKit.h>
#import "SubjectsController.h"
@interface OrderEntryAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UIViewController *welcomeController;
SubjectsController *subjectsController;
UINavigationController *navigationController;
NSString *pathToHere, *nextPath;
UIButton *startButton;
}
-(IBAction) start:(id)sender;
@property (nonatomic, retain) IBOutlet UIButton *startButton;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIViewController *welcomeController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSString *pathToHere, *nextPath;
@end
[B]OrderEntryAppDelegate.m[/B]
#import "OrderEntryAppDelegate.h"
#import "SubjectsController.h"
#import "UIKit/UIKit.h"
@implementation OrderEntryAppDelegate
@synthesize window;
@synthesize welcomeController;
@synthesize startButton;
@synthesize navigationController;
@synthesize pathToHere;
@synthesize nextPath;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions {
pathToHere = @"/";
//activate the start button
[startButton setHidden:NO];
//create navigation controller
navigationController =
[[UINavigationControlleralloc] initWithRootViewController: welcomeController];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void) start:(id)sender{
//create myTableViewController instance
subjectsController = [[SubjectsController alloc] initWithStyle:UITableViewStylePlain];
nextPath = [pathToHere stringByAppendingPathComponent:@"Subjects"];
[navigationController pushViewController:subjectsController animated:YES];
printf("The start button was tapped\n");
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
[B]SubjectsController.h[/B]
#import <UIKit/UIKit.h>
#import "OrderEntryAppDelegate.h"
@interface SubjectsController : UITableViewController {
NSString *pathToHere;
NSArray *dataArray;
}
@property (nonatomic, retain) NSString *pathToHere
@property (nonatomic, retain) NSArray *dataArray;
@end
[B]SubjectsController.m[/B]
#import "OrderEntryAppDelegate.h"
#import "SubjectsController.h"
@implementation SubjectsController
@synthesize pathToHere;
@synthesize dataArray;
- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if (self) {
// Custom initialization.
self.title = @"Conference Subjects";
}
return self;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
OrderEntryAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
NSError *error = nil;
self.pathToHere = [delegate nextPath];
dataArray = [[NSFileManager alloc] contentsOfDirectoryAtPath:delegate.pathToHere
error:&error];
return [dataArray count];
}
-(UITableViewCell *) tableView:tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
OrderEntryAppDelegate *delegate = [[UIApplication sharedApplication]delegate];
NSError *error = nil;
self.pathToHere = [delegate nextPath];
dataArray = [[NSFileManager alloc] contentsOfDirectoryAtPath:delegate.pathToHere
error:&error];
UITableViewCell *cell =
[self.subjectsViewdequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (!cell) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"UITableViewCell"] autorelease];
}
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
return cell;
}
/*-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
OrderEntryAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
delegate.nextPath = [pathToHere stringByAppendingPathComponent:selectedCell.textLabel.text];
conferencesController = [[ConferencesController alloc] initWithStyle:UITableViewStylePlain];
[delegate.navigationController pushViewController:conferencesController animated:YES];
printf("next Level\n");
}*/
@end
Last edited: