Quit an App designer GUI using a code - Matlab

Viewed 544

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
1 Answers

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
Related