开发者

AppDelegate global variable holds NULL value all time

I am facing very strange problem.. For my project I made 3 different modules now I am integrating them all..My problem is none of my global variable can hold values..It holds NULL all the time..

for example have a look at my PickerView code:

- (void)pickerView:(UIPickerVi开发者_如何学Cew *)thePickerView didSelectRow:(NSInteger)rowinComponent:(NSInteger)component 
{ 
  am=(AppMakerAppDelegate *)[[UIApplication sharedApplication]delegate]; 
  NSString *domainName = [NSString stringWithFormat:@"%@" , [array objectAtIndex:row]]; 
  am.url=domainName; 
  txtnewscategory.text = domainName; 
  am.catagory_title=[title1 objectAtIndex:row]; 
  NSLog(@"Domain:%@ --> %@ ",domainName,[array objectAtIndex:row]); 
} 

Here I get "domainName" value exactly but when its assigned to global variable am.url it shows null value.. Same case for "am.catagory_title"

Note:

1) url and catagory_title are declared in AppDelegate and both are NSString datatype.

2) am is appdelegate object and used like this..

  Appmaker_NewsInfoAppDelegate *am;
  am=(Appmaker_NewsInfoAppDelegate *)[[UIApplication sharedApplication]delegate];

Can anyone tell me what Am i doing wrong?? the code works perfectly at original project from where I exported it but doesn't when exported to integrate it.

Thanks..

Edit :

3) in Appmaker_NewsInfoAppDelegate.h(Delegate class where global variables are declared)

  NSString *url;


  @property(retain,nonatomic) NSString *url;


In case you didn't declare them as @property (retain), am.url needs to be retained, because stringWithFormat gives you an autoreleased object that won't survive this method call if not retained.

The same for catagory_title.

Retain them like this: am.url = [domainName retain];

But don't forget to release the previous value if you assign them elsewhere:

if (am.url != nil) { [am.url release]; }
am.url = [domainName retain];


Verify the property being set to "url" attribute of your app delegate. I hope it is not assign, instead you should use retain or copy.

In the sample code provided by you the domainName is an autoreleased object.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜