2

How can I quit an App designer GUI using a button?

I tried this and it does not work:

function QuitButtonPushed(app, event)
          fig = uifigure;
          selection = uiconfirm(fig,'Close software?','Quit', 'Icon','warning');  
          switch selection
          case 'Yes'
          app.delete;
          case 'No'
         return 
        end
AsiJapan
  • 313
  • 1
  • 10

1 Answers1

1

The switch case should be with 'OK' and 'Cancel' and not 'Yes', 'No'.

It is also recommended to pass app.UIFigure instead of using fig = uifigure;:

selection = uiconfirm(app.UIFigure,'Close software?','Quit', 'Icon','warning');

switch selection
    case 'OK'
        app.delete();
    case 'Cancel'
        return
end
Rotem
  • 30,366
  • 4
  • 32
  • 65