Skip to Content
0

How to Use FUIListPickerFormCell in SAP Fiori SDK for IOS

Apr 28, 2017 at 12:45 PM

109

avatar image

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

        }
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Florian Pfeffer
Apr 29, 2017 at 09:17 PM
0

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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.

0

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.

0

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.

0
Florian Pfeffer
May 05, 2017 at 05:21 AM
0

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
    }

}
Show 2 Share
10 |10000 characters needed characters left characters exceeded

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.

0

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.

0