0

Right now I have this code to show an alert view with a bunch of options for changing the blocks of something, its a basic scheduling app. But the options now go off the screen [see bottom], is there some way to shrink the view. I also looked into doing something with UIPickerview but it didn't look like it would work for the way this is currently set up

private func showChangeBlock() {
        
        let alert = UIAlertController(title: "Block", message: "During what block does this class meet?", preferredStyle: .actionSheet)
        
//      Array of tuples instead of dictionary so that it retains its order
        var blockActions: [(id: Block.ID, alert: UIAlertAction)] = []
        
        let handler: (UIAlertAction) -> Void = {
            alert in
            
//          Get the tuple with this specific action, and thus its blockId
            guard let key = blockActions.filter({ $0.alert === alert }).first?.id else {
                return
            }
            
            self.course.scheduleBlock = key
            self.tableHandler.reload()
            
            self.needsNotificationUpdate()
        }
        
        blockActions = [
            (.a, UIAlertAction(title: "A Block", style: .default, handler: handler)),
            (.b, UIAlertAction(title: "B Block", style: .default, handler: handler)),
            (.c, UIAlertAction(title: "C Block", style: .default, handler: handler)),
            (.d, UIAlertAction(title: "D Block", style: .default, handler: handler)),
            (.e, UIAlertAction(title: "E Block", style: .default, handler: handler)),
            (.f, UIAlertAction(title: "F Block", style: .default, handler: handler)),
            (.g, UIAlertAction(title: "G Block", style: .default, handler: handler)),
            (.x, UIAlertAction(title: "X Block", style: .default, handler: handler)),
            (.block1, UIAlertAction(title: "Block 1", style: .default, handler: handler)),
            (.block2, UIAlertAction(title: "Block 2", style: .default, handler: handler)),
            (.block3, UIAlertAction(title: "Block 3", style: .default, handler: handler)),
            (.block4, UIAlertAction(title: "Block 4", style: .default, handler: handler)),
            (.activities, UIAlertAction(title: "Activities", style: .default, handler: handler))
        ]
        
        for (id, action) in blockActions {
            if self.course.scheduleBlock == id {
                action.setValue(true, forKey: "checked")
            }
            
            alert.addAction(action)
        }
        
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        
        self.present(alert, animated: true)
    }

picture

  • 1
    I'm afraid UIAlertController is not the right Control to display that many options. I would build a UITableViewController and display the options there. When the user tabs one of options, navigate back to the view above. – Florian-Rh Aug 14 '20 at 06:05
  • The answer of @GuyMontag is right, but if you should check the answer of this question, maybe it can help you: https://stackoverflow.com/questions/25019701/how-to-change-uialertcontroller-height – goat_herd Aug 14 '20 at 07:40
  • If there are not multiple selections, I would suggest using UIPickerView instead of UIAlertController. – Saurabh Aug 14 '20 at 11:54
  • @GuyMontag thank you then! I will try that – Henry Price Aug 14 '20 at 14:18

0 Answers0