我有一種方法可以將輸入的客戶數據保存在調用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都保留