开发者

Sharing data conflicts between two View Controller using UIApplicationDelegate

I need to share data from a "SampleAppdelegate" to two view controller "ContactViewController.m" and "DrinksViewController.m".

In SampleAppdelegat开发者_C百科e:

@interface SampleAppdelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate , UINavigationBarDelegate>

So I've included below code in respective view controller.

In ContactViewController.m:

- (void)viewDidLoad   
{  
    [super viewDidLoad];  
    SampleAppDelegate *appDelegate = (SampleAppDelegate *)[[UIApplication sharedApplication] delegate];  
    contactDatabaseObject = (ContactDatabaseObject *)[appDelegate.contactDetails objectAtIndex:0];  
    NSLog(@"%@", contactDatabaseObject.contactName);  
    [appDelegate release];  
}

In DrinksViewController.m

(void)viewDidLoad  
{  
    [super viewDidLoad];  
    SampleAppDelegate *appDelegate = (SampleAppDelegate *)[[UIApplication sharedApplication] delegate];  
    drinksDatabaseObject = (DrinksDatabaseObject *)[appDelegate.drinkDetails objectAtIndex:0];  
    NSLog(@"%@", drinksDatabaseObject.drinkName);  
    [appDelegate release];  
}

The problem is "sharing application delegate is is both of the code not working at the same time. ( that is, if I comment above in a view controller then other is working fine as as expected).

Actually i'm using a tab-bar with two item as above viewControllers. So loading of the first controller happens fine. But when i click the second view controller the iphone-simulator is terminated with any warning. ( And at the same time the code works normal if I comment it in any one of the view controller). Please help me to resolve above issues or suggest a method to accomplish above feature.

Thanks in advance !


You should read ...

http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html

You're not owner of appDelegate, no need to release it.

P.S. If you're asking for help and writing something about warning, you should always copy warning here to shed more light on your problem.


You should not be releasing the appDelegate.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜