2

As far as I know, we can give a listener to Alert like "No" and "Exit" in showAlert. So if we pressed exit or ok we can do what we want.

Are you sure want to exit
Exit            No

Is it possible to put radioButton inside showAlert ? example :

o Juice
o Food
o Furniture
Exit   Go

Something like this, if i choose Juice and pressed Go, I will direct it to JuiceController. Is this can be done? or showAlert only can handle 2 action only ?

StevenTan
  • 275
  • 1
  • 5
  • 20

1 Answers1

2

please check this link . I made a project as per your requirement using actionSheet. you can just make use of this code for reference and embed it in your project

https://drive.google.com/open?id=0Bz8kF1Gedr7fd0JzcTh6c0JVMGs

As if you want to increase the height of action sheet yes you can do it

method 1 - Use this to increase actionSheet height and increase the height of view Embedded in it

func showAleert(){
        let alertController = UIAlertController(title: "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertControllerStyle.actionSheet) //if you increase actionSheet height to move default button down increase \n \n count and get your layout proper


        let margin:CGFloat = 10.0
        let rect = CGRect(x: margin, y: margin, width: alertController.view.bounds.size.width - margin * 4.0, height: 320)
        let customView = UIView(frame: rect)

        customView.backgroundColor = .clear //Background colour as clear

        customView.addSubview(buttonn)
        customView.addSubview(buttonn1)
        customView.addSubview(buttonn2)

        customView.addSubview(label)
        customView.addSubview(label1)
        customView.addSubview(label2)

        alertController.view.addSubview(customView)
        let ExitAction = UIAlertAction(title: "Go", style: .default, handler: {(alert: UIAlertAction!) in

            if self.juiceBool == true {
                //go to juice Controller
                print("juice")
            }
            if self.FoodBool == true{
                //go to food controller
                print("food")
            }
            if self.FurnitureBool == true{
                //go to furniture controller
                print("furniture")
            }
            if (self.juiceBool == false) && (self.FurnitureBool == false) && (self.FoodBool == false){
                //peform your operation like naything you want safety side
                print("Not selected Any")
            }


        })

        let height:NSLayoutConstraint = NSLayoutConstraint(item: alertController.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: self.view.frame.height * 0.80) //here you can define new height for action Sheet
        alertController.view.addConstraint(height);

        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {(alert: UIAlertAction!) in print("cancel")})
        alertController.addAction(ExitAction)
        alertController.addAction(cancelAction)
        DispatchQueue.main.async {
            self.present(alertController, animated: true, completion:{})
        }

    }

Method 2 - As a View is added you can add scrollView Anything you like IF your option Succeeds more than Like 10,30 or big in number make use of method 1 and give a proper height and then add a scroll view in embedded view with multiple buttons

or

you can just add upto 10 options if you modify actionSheet by using method 1

iOS Geek
  • 4,825
  • 1
  • 9
  • 30