尝试将字符串附加到NSTextField中的另一个字符串以打印在PDF文件上
问题描述:
我有一种方法可以将输入的客户数据保存在调用createPDFFile方法的表单中。我创建了PDF文件,目前我有一些填充字符串,这样我就可以布局PDF文件,现在我想从NSTextField获取stringValue,然后将其附加到包含ex的字符串的字符串:@ “Name:”追加NSTextField的stringValue。当我改变IBOutput保留并且为第一项而非第二项等工作时,我可以得到第一项工作。我得到了BAD_AXCESS错误,但只有当方法完成时。尝试将字符串附加到NSTextField中的另一个字符串以打印在PDF文件上
这里是PDF绘制方法的开始:
-(void)drawPDFCustomerInfoWithContext:(CGContextRef)currentContext andWithPageSize:(CGSize)pageSize andCustomerObject:(Customer *)currentCustomer{
CTFontRef font = CTFontCreateWithName(CFSTR("Arial"), 12, NULL);
CFRange currentRange = CFRangeMake(0, 0);
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
NSString *customerName = [[[@"Name: " stringByAppendingString:self.firstNameTextField.stringValue] stringByAppendingString:@" "] stringByAppendingString:self.lastNameTextField.stringValue];
NSString *customerAddress = @"Address: ";
NSString *customerCity = @"City: ";
NSString *customerState = @"State: ";
NSString *customerZipcode = @"Zipcode: ";
NSString *customerPhone = @"Phone: ";
NSString *customerEmail = @"Email: ";
CFStringRef customerNameStringRef = (__bridge CFStringRef)customerName;
CFStringRef customerAddressStringRef = (__bridge CFStringRef)customerAddress;
CFStringRef customerCityStringRef = (__bridge CFStringRef)customerCity;
CFStringRef customerStateStringRef = (__bridge CFStringRef)customerState;
CFStringRef customerZipCodeStringRef = (__bridge CFStringRef)customerZipcode;
CFStringRef customerPhoneStringRef = (__bridge CFStringRef)customerPhone;
CFStringRef customerEmailStringRef = (__bridge CFStringRef)customerEmail;
这里是保存方法:
- (IBAction)sendEstimateToCustomer:(id)sender {
float tempFloat = [[self.estimateNumberLabel stringValue]floatValue];
self.customerDataArray = [[NSMutableArray alloc]initWithArray:[self createCustomerDataArrayWithFirstName:self.firstNameTextField.stringValue andLastName:self.lastNameTextField.stringValue andAddress:self.customerAddress.stringValue andCity:self.customerCity.stringValue andState:self.customersState.stringValue andZipCode:self.customerZipcode.stringValue andPhone:self.customerPhone.stringValue andEmail:self.customerEmail.stringValue andEstimateNumber:tempFloat]];
self.customer = [[Customer alloc]initWithCustomerDataArray:self.customerDataArray];
[self createEstimatePDF];
这里是createEstimatePDF方法
-(void)createEstimatePDF{
NSLog(@"create Estimate Method Fired");
CGContextRef pdfContext;
CFURLRef url;
url = [self createPDFPath];
CFMutableDictionaryRef myDictionary = NULL;
myDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("Ben"));
pdfContext = CGPDFContextCreateWithURL(url,NULL, myDictionary);
CFRelease(url);
CGPDFContextBeginPage(pdfContext,myDictionary);
CGSize pageSize = CGSizeMake(612, 792);
[self drawPDFJobDescriptionTableWithContext:pdfContext andWithPageSize:pageSize];
[self drawPDFContractualTextWithContext:pdfContext andPageSize:pageSize];
[self drawPDFCustomerInfoWithContext:pdfContext andWithPageSize:pageSize andCustomerObject:self.customer];
[self drawPDFEstimateNumberWithContext:pdfContext andWithPageSize:pageSize];
[self drawPDFJobTableHeadersWithContext:pdfContext andPageSize:pageSize];
[self drawPDFBorderWithContext:pdfContext andWithPageSize:pageSize];
[self drawPDFHeaderWithContext:pdfContext andWithPageSize:pageSize];
[self drawPDFLegalStatementWith:pdfContext andPageSize:pageSize];
[self drawPDFSignatureAndDateWith:pdfContext andPageSize:pageSize];
[self drawPDFSignLinesWithContext:pdfContext andPageSize:pageSize];
CFRelease(myDictionary);
CGPDFContextEndPage(pdfContext);
我觉得有些事情正在获得释放,但我无法找到在哪里。我观察了这些变量并逐步完成,然后它们显示出所有值,然后显示该值,然后显示该方法的最后一个右括号,然后显示BAD_ACCESS错误。我才不会对立场是,这个工程,
NSString *customerName = [[[@"Name: " stringByAppendingString:self.firstNameTextField.stringValue] stringByAppendingString:@" "] stringByAppendingString:self.lastNameTextField.stringValue];
香港专业教育学院试图值超过以及通过复制方法与客户对象传递来传递数据也是如此。
如果需要更多信息,我可以提供。所有NSTextfields都保留
答
的问题是在我被释放,是造成它被画之前,我相信丢失的价值CFStringRef函数结束时,我删除了
CFRelease(customerNameStringRef);
和那么它似乎适用于所有人。