Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
This is driving me potty and I just can't figure out where I am going wrong!

Lets say I have an app delegate and three classes:

AppDelegate, Class1, Class2 and Class3

In AppDelegate I have an NSArray instance variable called ....Barry (lol)
I also have in AppDelegate an NSUinteger outside of the interface block to hold the value of an indexPath from a table call.

In Class1 I can import the app delegate .h file, create a reference to Barry using this reference and read and write its values.

When I step through the code in debug I can see that instanceOfAppDelegate.Barry has been set and contains the one object Class1 writes to it.

But if I then try the same thing in Class3 which is different from Class1 but needs to access Barry I do not get any errors but when querying instanceOfAppDelegate.Barry in Class3 it remains unset as it I dont think it is pointing to Barry in AppDelegate

???
 

beardedpig

macrumors member
Original poster
Dec 17, 2008
57
0
good point!

AppDelegate.h

Code:
#import <UIKit/UIKit.h>

NSUInteger rowIndex;

@interface AppDelegate : NSObject <UIApplicationDelegate> {
    
    UIWindow *window;
    UINavigationController *navigationController;
	
    NSArray *Barry;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (retain, nonatomic) NSArray *Barry;

@end

AppDelegate.m

Code:
#import "AppDelegate.h"
#import "Class1.h"

@implementation AppDelegate

@synthesize window;
@synthesize navigationController;
@synthesize Barry;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	
	// Configure and show the window
	[window addSubview:[navigationController view]];
	[window makeKeyAndVisible];
}

- (void)dealloc {
	[navigationController release];
	[window release];
	[Barry release];
	[super dealloc];
}

@end

Class1.h

Code:
#import <UIKit/UIKit.h>

@class AppDelegate;

@interface Class1 : UITableViewController <UITableViewDelegate, UITableViewDataSource> 
{	
	AppDelegate *myAppDelegate;
}

@property (retain, nonatomic) AppDelegate *myAppDelegate;

@end

Class.m

Code:
myAppDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];

rowIndex = [indexPath row];
	 
NSDictionary *rowData = [myAppDelegate.Barry objectAtIndex: rowIndex];
	
....

And here is the result of the German panel....beardedpig nil point!

I had not placed this line in Class3

Code:
myAppDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];

So by doing this little exercise I found my doofish error!!!!!

Thanks ;-)))
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.