hi there, I my program I need to pass MSMutableArrays from one to another viewcontrollers but I', not sure if the "basic scheme" of my program is ok..
I handle all conection voids and xmlparser in main controller.. is it good way?
shouldn't I handle this in AppDelegate.m file? I'm just unsure about if I doing it good (it is working but still..)
and another, for passing data I shouldn't use global variables so I should use delegate.. I make a simple example but it is not working
AppDelegate.h
Code:
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
NSMutableArray *pole;
}
@property (nonatomic, retain) NSMutableArray *pole;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
AppDelegate.m
Code:
@synthesize pole;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
pole = [[NSMutableArray alloc] init];
NSString * f = @"foo";
NSString * b = @"bar";
NSString * z = @"baz";
pole = [NSMutableArray arrayWithObjects:f,b,z,nil];
for (id obj in pole){
NSLog(@"%@", obj);
}
return YES;
}
ViewController.m
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *temp = appDelegate.pole;
// NSLog(@"%i",temp);
for (id obj in temp){
NSLog(@"%@", obj);
}
}
so.. red ones are my added code.. in AppDelegate.m is code working - NSLOG is giving me the foo bar baz items but in ViewController.m not.. so.. what I didn't understand there..?