开发者

Odd App Delegate Problem

In my app delegate, I have multiple NSStrings, declared like so

@property (nonatomic, retain) NSString *aString;

When my view first loads up, the string values are set

appDelegate.aString = @"aValue";

Where appDelegate is

self.appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

This all works fine, but for some reason, i开发者_如何学Got does not work on my iPad. It works on the simulator for iPad and iPhone (it is universal) and my iPhone. It was working earlier and I have not messed with it. Whenever I try to access the value after setting it, it returns null. Any ideas on what I should do?

EDIT 1: What I am trying to do is read a property list and if the value is null, I will manually set it like this:

if (appDelegate.aString == (id)[NSNull null] || appDelegate.aString.length == 0 ) {
        appDelegate.aString = @"aValue";
}

I put a NSLog in the if statement above so I know the code is being executed, but when I try to log aString, it still comes out null, even though I just set it.

I will also add that all the devices are running 4.3.x.

EDIT 2: If I set the value in applicationDidFinishLaunching, it does not come out null, which means there must be a problem setting the value from the view controller. I don't understand why it would not work on just one device though.


Unless you're explicitly using NSNull elsewhere, try using if (appDelegate.aString == nil || ... or even just if (!appDelegate.aString || ....


add a method in appdelegate with name

- (void) setaString:(NSString*) str{
//add logs and breakpoints here
}

Chances are 1. Some thing else is accessing the string. 2. string is being released somewhere.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜