0

i'm trying to add a "save before quit" alert on my app to avoid data loss if the user want to go back without saving on the previous view. I know there's a lot of method, but why this doesn't seems to work?

1) declare this two variables:

@property (nonatomic, assign) BOOL isChanged;

2)

@property (nonatomic, assign) NSString *modifiedText;

3) set to false "isChanged" at the init

4)

  (void)textFieldDidBeginEditing:(UITextField *)textField {
  self.modifiedText = textField.text;

5)

 - (void)textFieldDidEndEditing:(UITextField *)textField {

 if(![self.modifiedText isEqualToString:textField.text]){
        self.isChanged = YES;
 }
 else{
        self.isChanged = NO;
  }

But i've a exc_bad_access on modified text on 5. Why?

Retro
  • 3,985
  • 2
  • 17
  • 41
Alessio Crestani
  • 1,602
  • 4
  • 17
  • 38

3 Answers3

1

Try to declare modifiedText property this way:

@property (copy) NSString *modifiedText;

See this question for more information.

Community
  • 1
  • 1
iOS Dev
  • 4,143
  • 5
  • 30
  • 58
1

Try this

@property (nonatomic,retain) NSString *modifiedText;

or

@property (nonatomic,copy) NSString *modifiedText;

Instead of assign.

Gyanendra Singh
  • 1,483
  • 12
  • 15
1

Try this,

Change your property

@property (nonatomic, assign) NSString *modifiedText;

to

@property (nonatomic, strong) NSString *modifiedText;

more details

Community
  • 1
  • 1
Akhilrajtr
  • 5,170
  • 3
  • 19
  • 30