我在将四个标签的值从警报控制器传递到另一个tableViewController中的新单元格时遇到麻烦。我不确定我是否使用最佳方法将其传递给“添加”操作。

以下是相关片段->

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
   }


从产品TVC中提取序列“ addProduct”,以将故事板上的VC表视图定级为故事详细序列。

我在控制台上得到一个LLDB
让orderVC = storyBoard.instantiateViewControllerWithIdentifier(“ addProduct”)为! OrderViewController
警告:无法从dyld共享缓存中加载任何Objective-C类信息。这将大大降低可用类型信息的质量。

我希望有人帮助我完成这部戏,因为我有点迷失了。

最佳答案

我对使用代码要实现的目标感到很困惑。但是,在不尝试进一步分析的情况下,我可以为您提供一些有关流程应该如何的建议。您应该在此处调用的方法是prepareForSegue

didSelectRowAtIndexPath触发时,您执行segue addProduct

然后从prepareForSegue传递信息

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "addProduct") {
        let destination = segue.destinationViewController as! OrderViewController
        let indexPath = tableView.indexPathForSelectedRow
        let product = frc.objectAtIndexPath(indexPath) as! ProductItem
        destination.productcodeString = product.productcode as! String
    }
}

10-08 07:30