iPhone, Need to check if values have changed before I update my database?
I've gone for a simple approach, I've created some NSString variables w开发者_JAVA百科hich I set when the view load...
strKeptDesc = txtDescription.text;
NSLog(@"KDesc =#%@# CDesc =#%@#",strKeptDesc, txtDescription.text);
Which works as excepted and output the values you'd expect.
However in my db commit function, when I check the variables I get errors...
NSMethodSignature: 0x5c3fa80># CDesc =#Gas bill3#
Program received signal: “EXC_BAD_ACCESS”.
In my h file I have
NSString *strKeptDesc;
}
@property (nonatomic, retain) NSString *strKeptDesc;
I synthesize too.
strKeptDesc = txtDescription.text;
in this line you simply assign a string value to your iVar and your accessor methods do not get called - so if you're assigning autoreleased string it may be released and become invalid. You must write
self.strKeptDesc = txtDescription.text;
instead, so strKeptDesc will be retained in setter and remain valid outside the current method.
精彩评论