tags:

views:

28

answers:

1

I want to declare nsstring in uiviewcontroller.h file and use this string as whole uiviewcontroller , we want to set and get string values using these strings. I defined viewcontroller .h file like this

NSString *SelectedString;

For some time it released string values and crashes app nothing shows in log.

can anyone help me ?

+1  A: 

Are you trying to declare this as a public ivar? (instance variable) of your UIViewController .. ?

You would need something like for example:

(header)

#import <UIKit/UIKit.h>

@interface YourViewController : UIViewController {
    NSString *selectedString;
    ...
    ...
}

@property (nonatomic, retain) NSString *selectedString;
...
...
@end

(implementation file)

#import "YourViewController.h"

@implementation YourViewController
@synthesize selectedString;
...
...

-(void) dealloc {
    [selectedString release];
    [super dealloc];
}

...
...

@end

That's the basic memory management. If it's crashing somewhere in runtime, you need to clarify...how are you assigning strings/values and utilising the variable?

DJ Bouche
You're missing `@end` in both files ;)
Douwe Maan
haha, thanks.. fixed and added some ellipsis too to indicate they are [very much] incomplete source files :)
DJ Bouche
To add to this: the @property (nonatomic, retain) + @synthesize essentially create a getter and setter method for you i.e setselectedString: that will handle the retain count of the ivar for you
davbryn