开发者

NSMutableArray doesn't allocate right in my AppDelegate [closed]

开发者 https://www.devze.com 2023-03-23 22:13 出处:网络
开发者_高级运维 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
开发者_高级运维 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I made an NSMutableArray in my AppDelegate and I'm trying to add/get objects from one of my ViewControllers. I already made the viewController a sharedApplication so I know it's not that. I'm pretty sure it's a problem with the allocating of the NSMutableArray. I tried allocating it in this method of the AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    


//sleep(3);

coupons = [[NSMutableArray alloc] init];

[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];

return YES;
}

Coupons being the NSMutableArray

But then my app doesn't load on my device! Where should I put the allocating code!?


i had also try and got success. my code is.

in AppDelegate.h

NSMutableArray *coupons;
@property (nonatomic , retain) NSMutableArray *coupons; 

in AppDelegate.m

@synthesize coupons;
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    {    
        coupons=[[NSMutableArray alloc] init];
        [self.window addSubview:viewController.view];
        [self.window makeKeyAndVisible];
        return YES;
    }

in viewcontroller.h #import AppDelegate.h and

@interface testViewController : UIViewController 
{
 testAppDelegate *appdeleate;
}

in viewcontroller.m

- (void)viewDidLoad {
    [super viewDidLoad];
 appdeleate=[[UIApplication sharedApplication]delegate];
  [appdeleate.coupons addObject:@"one"];
  [appdeleate.coupons addObject:@"two"];
  [appdeleate.coupons addObject:@"three"];
  [appdeleate.coupons addObject:@"fore"];
  [appdeleate.coupons addObject:@"five"];
  [appdeleate.coupons addObject:@"six"];
 NSLog(@"%@",appdeleate.coupons);
}

It is work perfect for me, Hope it help you also.

0

精彩评论

暂无评论...
验证码 换一张
取 消