confirmationDialog crashes with Button.init(action, @ViewBuilder label)

My app gets killed with the error message: Actions added to UIAlertController of style UIAlertActionStyleDefault must have a title when running in UIUserInterfaceIdiomPhone

if I use one sort of button, but not the shorter sort. This code produces the error, but it I remove the button with Image(systemName:) I get that error.

Button(action: { showingExtras = true } ) { 
   Image(systemName: "ellipsis.rectangle") 
}
  .confirmationDialog("Extras", isPresented: $showingExtras) {
    Button(action: { showingCashSummary = true} )  {
      Image(systemName: "banknote")
    }
    Button("Cash summary") { showingCashSummary = true }
    Button("Allocation summary") {showingAllocationSummary = true}
    Button("Export") { isExporting = true }
}

Is there some way to add the title that UIAlertController requires?

Accepted Reply

Check the help for confirmationDialog. It states

On iOS, tvOS, and watchOS, confirmation dialogs only support controls with labels that are Text. Passing any other type of view results in the content being omitted.

  • I did see that, but I don't automatically have a good idea of what it means. I'm used to declarative UI libraries like Cocoa and Delphi, where the views would be represented by objects of a class, and have a property "label" or "text" or whatever. The code for confirmation dialog could read that, but in SwiftUI, as we have here, the Button is a black box, so it is not clear how it can read the label string. It's a hidden requirement. Grrrr. I hate those.

Add a Comment

Replies

Check the help for confirmationDialog. It states

On iOS, tvOS, and watchOS, confirmation dialogs only support controls with labels that are Text. Passing any other type of view results in the content being omitted.

  • I did see that, but I don't automatically have a good idea of what it means. I'm used to declarative UI libraries like Cocoa and Delphi, where the views would be represented by objects of a class, and have a property "label" or "text" or whatever. The code for confirmation dialog could read that, but in SwiftUI, as we have here, the Button is a black box, so it is not clear how it can read the label string. It's a hidden requirement. Grrrr. I hate those.

Add a Comment