Reputation: 11297
@interface SignDocumentController : UIViewController<NSXMLParserDelegate> {
NSMutableString *signFaxString;
NSString * messageId;
NSMutableData *xmlData;
NSURLConnection *connectionInprogress;
NSURLConnection *connectionInprogress2;
NSString * annotationKey;
NSString *firstName;
NSString *lastName;
NSString *date;
NSString *signature;
IBOutlet UIImageView *image;
}
@property(nonatomic,retain)UIImageView * image;
@end
-(void)parser:(NSXMLParser *)parser
didStartElement:(NSString *) elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqual:@"SignatureInfo"]) {
signFaxString = [[NSMutableString alloc]init];
firstName = [attributeDict objectForKey:@"FirstName"];
lastName = [attributeDict objectForKey:@"LastName"];
date = [attributeDict objectForKey:@"Date"];
signature = [attributeDict objectForKey:@"Signature"];
}
if ([elementName isEqual:@"AddAnnotationResult"]) {
signFaxString = [[NSMutableString alloc]init];
}
}
the values for firstName, lastName, date, signature do not stay and I get an error when I try accessing firstName, lastName ETC in a different method:
[CFString respondsToSelector:]: message sent to deallocated instance 0x4ec63b0
I have tried using :
firstName = [NSString stringWithString attributeDict objectForKey:@"FirstName"];
but that does not work either. I know this is a silly question but I could use some help.
Thanks
Upvotes: 0
Views: 160
Reputation: 31722
you could also declare the firstName
and others as property and retain
. As below
@property(nonatomic,retain)NSString* firstName;
@property(nonatomic,retain)NSString* lastName;
@property(nonatomic,retain)NSString* date;
@property(nonatomic,retain)NSString* signature;
And in .m class.
@synthesize firstName,date,lastName,signature;
and release them in dealloc
function.
Use with self
all your property variable in you class.
self.firstName = [NSString stringWithString:attributeDict objectForKey:@"FirstName"];
EDITED:
Also consider @bbum comment ..
Upvotes: 3
Reputation: 44633
To retain it, just send a retain
message to the object.
firstName = [[attributeDict objectForKey:@"FirstName"] retain];
release
it later.
Upvotes: 2