Skip to Content
avatar image
Former Member

How to Use FUIListPickerFormCell in SAP Fiori SDK for IOS

I have followed the document as it is but always get an exception when I click on the cell to change value. Bad execution.

Also I have to long press in my simulator normal press does nothing.

Below is my code

var propValue7: [Int] = [0]

        let valueOptions7 = ["YK ROADWAYS", "Transporter B", "Transporter C"]

        let cell = tableView.dequeueReusableCell(withIdentifier: FUIListPickerFormCell.reuseIdentifier, for: indexPath) as! FUIListPickerFormCell

        print(indexPath.row)

        cell.isEditable = true

//        cell.keyName = "\(order.vehicleType), \(order.vehicleRoute), \(order.totalWeight.round(1)), - \(order.noOfVehicles) vehicles"

//        cell.value = "\(order.transporter)"

//        let text = order.noOfVehicles == 1? "vehicle":"vehicles"

        let vehicleString: String = order.noOfVehicles == 1 ? "vehicle":"vehicles"

        cell.keyName = "\(order.vehicleType), \(order.vehicleRoute), \(order.totalWeight.round(1)), - \(order.noOfVehicles) \(vehicleString)"

        cell.value = propValue7

        cell.allowsMultipleSelection = false

        cell.valueTextField.text = descriptionForSelectedStrings(valueOptions7, at: propValue7) // See below

        cell.valueOptions = valueOptions7

        cell.listPicker.dataSource = nil

        print("\(cell.listPicker)")

//        cell.listPicker.searchResultsUpdating = listPickerDataSource7

//        cell.listPicker.isSearchEnabled = false

//        cell.listPicker.prompt = "Please select multiple items"

//        cell.delegate = DetailTableDelegate

        

//        cell.listPicker.searchBar?.isBarcodeScannerEnabled = true

//        cell.listPicker.searchBar?.barcodeScanner?.scanMode = .EAN_UPC

//        cell.listPicker.searchBar?.barcodeScanner?.scanResultTransformer = { (scanString) -> String in

//            return self.transformStringToSearchBar(scanResultString: scanString)

//        }

        // MARK:  implement onChangeHandler

        cell.onChangeHandler = { [unowned self] newValue in

            propValue7 = newValue

        }
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Apr 29, 2017 at 09:17 PM

    Have you defined the propValue7 variable locally in the tableview(:cellForRowAt) method or as property in the class? You have to define it as property in the class (or an object referenced by the class) so that it is available when the onChangeHandler method is executed.

    Regards,
    Florian

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Yes I have done that.

      It would be great help if you could help me out with any step wise tutorial or if you can list down all the steps required.

      Docs is not clear or may be its not working in my case.

      Thanks.

  • May 05, 2017 at 05:21 AM

    As requested in the comments here is a "quick and dirty" implementation of the table view controller. Consider that I did remove some parts of your code (e.g. the setting of the cell.valueTextField.text property). You have to add adjust the coding for your requirements

    import UIKit
    import SAPFiori
    
    class TableViewController: FUIFormTableViewController {
    
        var propValue7: [Int] = [0]
        var valueOptions7 = ["YK ROADWAYS", "Transporter B", "Transporter C"]
    
        override func viewDidLoad() {
            super.viewDidLoad()
            
            tableView.register(FUIListPickerFormCell.self, forCellReuseIdentifier: FUIListPickerFormCell.reuseIdentifier)
            
            tableView.estimatedRowHeight = 80
            tableView.rowHeight = UITableViewAutomaticDimension
        }
    
        // MARK: - Table view data source
        override func numberOfSections(in tableView: UITableView) -> Int {
            return 1
        }
    
        override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 1
        }
    
        override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            
            let cell = tableView.dequeueReusableCell(withIdentifier: FUIListPickerFormCell.reuseIdentifier, for: indexPath) as! FUIListPickerFormCell
            
            print(indexPath.row)
            
            cell.keyName = "Vehicles"
            cell.value = propValue7
            cell.allowsMultipleSelection = false
            cell.valueTextField.text = "..."
            cell.valueOptions = self.valueOptions7
            cell.listPicker.prompt = "Please select a value"
            
            cell.onChangeHandler = { [unowned self] newValue in
                self.propValue7 = newValue
            }
    
            return cell
        }
    
    }
    
    Add comment
    10|10000 characters needed characters exceeded

    • No, UIKit is not necessary in an explicit way.

      If your table view controller inherits from FUIFormTableViewController, your table view controller is embedded in a navigation controller and if your coding matches than one like described in the documentation (or the dummy example above) it should work.