FUIUserConsentPageViewController
open class FUIUserConsentPageViewController : FUIBaseDrawingViewController<FUIUserConsentPageView>, FUISolidNavigationBarProtocol, UIScrollViewDelegate
This UIViewController
is used to display a simple form to the user to obtain consent. The form contains a title
property, body
property containing the details and a link to more information, which when clicked invokes the actionHandler
. The text of the link can be set with the actionTitle
property. There are 2 buttons in the toolbar, “Deny” and “Agree”, if the form’s isMandatory
property is true or “Not Now” and “Agree”, if it is false. The toolbar button titles can also be changed using the toolbarLeftItemTitle
and toolbarRightItemTitle
properties. The toolbar buttons invoke the FUIConsentPageViewControllerDelegate
methods which can be used to handle the application logic based on the user input. Note that this class must only be used when displaying a simple form with information that fits in a single page (controller). While using modal presentation style, the controller must be embedded in a navigation controller to display the toolbar.To display a series of consent forms (where each form may span a single page or multiple pages), please refer to FUIUserConsentViewController.
The above image shows the form displayed using the push segue. Sample code to do that is provided below.
// Sample code to create a controller as a subclass of FUIUserConsentPageViewController and display it using push segue
import Foundation
import SAPFiori
class SimpleFormUsingPushSegue: FUIUserConsentPageViewController, FUIUserConsentPageViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Push Segue Example"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
open override func viewDidLayoutSubviews(){
super.viewDidLayoutSubviews()
}
func didAllow(_ controller: FUIUserConsentPageViewController) {
print("Did Allow")
self.navigationController?.popViewController(animated:true)
}
func didDeny(_ controller: FUIUserConsentPageViewController) {
print("Did Deny")
self.navigationController?.popViewController(animated:true)
}
}
// Sample code to display the above form using push segue
let ctrllr = SimpleFormUsingPushSegue()
ctrllr.userConsentPageViewControllerDelegate = ctrllr
ctrllr.title.text = "A Simple Form"
ctrllr.body.text = " Use this controller to display a single page form to the user"
ctrllr.actionTitle.text = "More Details"
ctrllr.actionHandler = { controller in
let alert = UIAlertController(title: "Details", message: "Visit sap.com", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title:"OK", style: UIAlertActionStyle.default, handler: nil))
controller.present(alert, animated: true, completion: nil)
}
ctrllr.isMandatory = true
self.navigationController?.pushViewController(ctrllr, animated: true)
The above image shows the form displayed using modal segue. Sample code to do that is provided below.
// Sample code to create a controller as a subclass of FUIUserConsentPageViewController and display it modally
import Foundation
import SAPFiori
class SimpleFormUsingModalSegue: FUIUserConsentPageViewController, FUIUserConsentPageViewControllerDelegate
{
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
open override func viewDidLayoutSubviews(){
super.viewDidLayoutSubviews()
}
func didAllow(_ controller: FUIUserConsentPageViewController) {
print("Did Allow")
self.dismiss(animated: true, completion: nil)
}
func didDeny(_ controller: FUIUserConsentPageViewController) {
print("Did Deny")
self.dismiss(animated: true, completion: nil)
}
@objc func leftBarButtonClicked(sender: UIBarButtonItem) {
let alert = UIAlertController(title: "Are you sure you want to cancel?", message:nil , preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Quit", style: .default, handler: { action in
self.navigationController?.dismiss(animated: true, completion:nil)}))
self.navigationController?.topViewController?.present(alert, animated: true, completion: nil)
}
}
// Sample Code to display the above controller modally
var navController = UINavigationController()
let ctrllr = SimpleFormUsingModalSegue()
ctrllr.userConsentPageViewControllerDelegate = ctrllr
ctrllr.title.text = "A Simple Form"
ctrllr.body.text = " Use this controller to display a single page form to the user"
ctrllr.actionTitle.text = "More Details"
ctrllr.actionHandler = { controller in
let alert = UIAlertController(title: "Details", message: "Visit sap.com", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
controller.present(alert, animated: true, completion: nil)
}
ctrllr.isMandatory = true
ctrllr.toolbarLeftItemTitle = "Left"
ctrllr.toolbarRightItemTitle = "Right"
navController = UINavigationController(rootViewController: ctrllr)
let cancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(leftBarButtonClicked))
navController.topViewController?.navigationItem.leftBarButtonItem = cancelButton
self.present(navController, animated: true, completion: nil)
// Add a cancel button to the navigation controller when displaying the form modally.
@objc func leftBarButtonClicked(sender: UIBarButtonItem) {
let alert = UIAlertController(title: "Are you sure you want to cancel?", message:nil , preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Quit", style: .default, handler: { action in
self.navController.dismiss(animated: true, completion:nil)}))
self.navController.topViewController?.present(alert, animated: true, completion: nil)
}
-
Boolean denoting whether the form displayed is a mandatory form or not.
Declaration
Swift
open var isMandatory: Bool
-
String denoting the title of the left toolbar button item. If the developer does not provide a non-empty string for the value, then the left toolbar button title appears as “Deny”(if isMandatory is true) or “Not Now”(if isMandatory is false).
Declaration
Swift
open var toolbarLeftItemTitle: String
-
String denoting the title of the right toolbar button item. If the developer does not provide a non-empty string for the value, then the right toolbar button title appears as “Deny”(if isMandatory is true) or “Not Now”(if isMandatory is false).
Declaration
Swift
open var toolbarRightItemTitle: String
-
An implementation of
FUIUserConsentPageViewControllerDelegate
to handle user actions.Declaration
Swift
open weak var userConsentPageViewControllerDelegate: FUIUserConsentPageViewControllerDelegate?
-
Undocumented
Declaration
Swift
public func scrollViewDidScroll(_ scrollView: UIScrollView)