cancel
Showing results for 
Search instead for 
Did you mean: 

How to Use FUIListPickerFormCell in SAP Fiori SDK for IOS

Former Member
0 Kudos

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

        }

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Cant i use form cells without subclassing FUIFormTableViewController? Because my viewcontroller has to embed with UIview and a tableview

pfefferf
Active Contributor
0 Kudos

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
    }

}
Former Member
0 Kudos

Do I need to import UIKit as well with SAPFiori??

That is probably the only thing I have missed.

Also I am using it in a modal so does that affect it in any way.

Edit: I tried importing UIKit as well but same issue.

pfefferf
Active Contributor
0 Kudos

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.

pfefferf
Active Contributor
0 Kudos

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

Former Member
0 Kudos

If you check the first line of my pasted code I have defined it

var propValue7: [Int] = [0]

so it should work in the onChangeHandler.

Also the list of options does not open at all.

pfefferf
Active Contributor
0 Kudos

It will work in such a way that you get no crash, but in case the propValue7 is locally defined, the selected value will not change.

But that you get also no the list with the values to be selected is an "nice" further information, which issue is not related to that.

Did you check if your table view controller implementation is inherited from class FUIFormTableViewController. If that is not the case you will get a crash in case you click on the cell in order to navigate to the value list.

Former Member
0 Kudos

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.