我正在使用Swift和Xcode 6.1。我有一个在IB中构建的表单,其中包含一个由Array提供的TableView。我正在使用一个只捕获视图的系统 将其转换为PDF文件: -
UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil)
UIGraphicsBeginPDFPage()
self.view.layer.renderInContext(pdfContext)
UIGraphicsEndPDFContext()
代码只适用于数组中不超过第一个表大小的一组值,但我需要捕获每个表 使用数组值。
想象一下包含页码和未知行数的发票。
我已将行限制设置为10但是无法找到捕获序列的方法,即: -
pdfData.writeToFile(documentDirectoryFilename, atomically: true)
https://www.dropbox.com/s/1stlw9gu44f7iyx/shot.png?raw=1
该表仅由标准驱动: -
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as OrderFormCell
var data = Orders[indexPath.row]
let netFloat = data.valueForKey("net") as Float
cell.netPriceLabel.text = NSString(format: "£%.2f", netFloat)
cell.bookOrderLabel.text = data.valueForKey("book") as String?
cell.bookOrderLabel.sizeToFit()
cell.isbnLabel.text = data.valueForKey("isbn") as String?
// ----- Int to String -------------------
let quantityAsInt : Int = data.valueForKey("quantity") as Int!
cell.quantityLabel.text = "\(quantityAsInt)"
// -------- NString to Float -------------
let bb : NSString = cell.quantityLabel.text!
bookValue = data.valueForKey("booktotal") as Float
cell.bookNetValueOutlet.text = NSString(format: "£%.2f", bookValue)
totalValueOutlet.text = NSString(format: "£%.2f", totalValue)
return cell
}
谢谢,
安东尼