【发布时间】:2016-06-09 03:58:33
【问题描述】:
我在将四个标签的值从警报控制器传递到另一个 tableViewController 中的新单元格时遇到了一些问题。我不确定我是否使用最佳方法将其传递给“添加”操作。
这里是相关的sn-ps ->
ProductTableViewController.swift
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! ProductTableViewCell
// Get the row data for the selected row
let product = frc.objectAtIndexPath(indexPath) as! ProductItem
cell.productcodeLabel.text = product.productcode
cell.detailLabel.text = product.detail
cell.quantityLabel.text = "MOQ \(product.quantity as! Double)"
cell.barcodeLabel.text = product.barcode
//MARK: - Add Item Alert
var quantityTextField = UITextField()
let alertController = UIAlertController(title: "\(product.detail!)\n \("MOQ \(product.quantity as! Double)")", message: nil, preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: {(alert: UIAlertAction!) in print("Cancel Button Pressed")
alertController.dismissViewControllerAnimated(true, completion: nil)
})
let action = UIAlertAction(title: "Add", style: .Default, handler: { (action) -> Void in
// Now do whatever you want with inputTextField (remember to unwrap the optional)
quantityTextField = alertController.textFields![0] as UITextField
print("Add Button Pressed")
print("You entered \(product.productcode!) \(quantityTextField.text!)")
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let orderVC = storyBoard.instantiateViewControllerWithIdentifier("addProduct") as! OrderViewController
orderVC.productcodeString = product.productcode! as String!
orderVC.detailString = product.detail! as String!
orderVC.quantityString = quantityTextField.text! as String!
orderVC.barcodeString = product.barcode! as String!
self.navigationController?.pushViewController(orderVC, animated: true)
})
alertController.addTextFieldWithConfigurationHandler{ (quantityTextField) -> Void in
quantityTextField.placeholder = "Enter quantity here..."
quantityTextField.font = UIFont.systemFontOfSize(15)
quantityTextField.autocorrectionType = UITextAutocorrectionType.No
quantityTextField.keyboardType = UIKeyboardType.NumberPad
quantityTextField.returnKeyType = UIReturnKeyType.Done
quantityTextField.clearButtonMode = UITextFieldViewMode.WhileEditing;
quantityTextField.contentVerticalAlignment = UIControlContentVerticalAlignment.Center
quantityTextField.delegate = self
}
alertController.addAction(cancelAction)
alertController.addAction(action)
self.presentViewController(alertController, animated: true, completion:{})
}
OrderViewController.swift
class OrderViewController: UITableViewController{
var productcodeString = String()
var detailString = String()
var quantityString = String()
var barcodeString = String()
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("OrderCell", forIndexPath: indexPath) as! OrderTableViewCell
// Configure the cell...
cell.productcodeLabel.text = productcodeString
cell.detailLabel.text = detailString
cell.quantityLabel.text = "X \(quantityString)"
cell.barcodeLabel.text = barcodeString
return cell
}
segue“addProduct”是从 productTVC 中提取的,以作为情节提要中的 orderVC tableviews 的显示细节 segue。
我在控制台中得到一个 LLDB 就行了 让 orderVC = storyBoard.instantiateViewControllerWithIdentifier("addProduct") 为!订单视图控制器 警告:无法从 dyld 共享缓存加载任何 Objective-C 类信息。这将显着降低可用类型信息的质量。
我希望有人可以帮助我完成这部戏剧,因为我有点失落。
【问题讨论】:
-
什么时候出现这个错误?
-
当我点击警报中的添加按钮时。
标签: ios swift segue uialertcontroller didselectrowatindexpath