gpt4 book ai didi

objective-c - 如何在以下方法中保留值?

转载 作者:行者123 更新时间:2023-11-28 18:44:29 26 4
gpt4 key购买 nike

@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];
}


}

名字、姓氏、日期、签名的值不会保留,当我尝试以不同的方法访问名字、姓氏等时出现错误:

[CFString respondsToSelector:]: 发送到释放实例 0x4ec63b0 的消息

我试过使用:

firstName = [NSString stringWithString attributeDict objectForKey:@"FirstName"]; 

但这也不起作用。我知道这是一个愚蠢的问题,但我需要一些帮助。

谢谢

最佳答案

您还可以将 firstName 和其他声明为属性并 retain 。如下图

@property(nonatomic,retain)NSString* firstName;
@property(nonatomic,retain)NSString* lastName;
@property(nonatomic,retain)NSString* date;
@property(nonatomic,retain)NSString* signature;

在 .m 类中。

@synthesize firstName,date,lastName,signature;

并在 dealloc 函数中释放它们。

self 一起使用您类中的所有属性变量。

self.firstName = [NSString stringWithString:attributeDict objectForKey:@"FirstName"];

已编辑:

同时考虑 @bbum 评论..

关于objective-c - 如何在以下方法中保留值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6515618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com