dragon
dragon

Reputation: 317

NSString for uiviewcontroller

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 ?

Upvotes: 0

Views: 295

Answers (1)

DJ Bouche
DJ Bouche

Reputation: 1164

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?

Upvotes: 1

Related Questions