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 h开发者_开发技巧elp me ?
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?
精彩评论