objective c - How to make the NSAlert's 2nd button the return button? -
i'd make nsalert:
as can see, 'return' button second one. how can this?
here's example of code use create nsalert, first button gets focus:
nsalert *alert = [[nsalert alloc] init]; [alert setmessagetext:@"are sure want disconnect?"]; [alert addbuttonwithtitle:@"disconnect"]; [alert addbuttonwithtitle:@"cancel"]; [alert runmodal]; i want focus "cancel" button. ideas? thanks!
to change key equivalents nsbutton elements inside of nsalert object, you'll have access buttons directly (after creation , before -runmodal) , change key equivalents using -setkeyequivalent: method.
for example, set disconnect esc , cancel return, following:
nsarray *buttons = [alert buttons]; // note: rightmost button index 0 [[buttons objectatindex:1] setkeyequivalent: @"\033"]; [[buttons objectatindex:0] setkeyequivalent:@"\r"]; before calling -runmodal
Comments
Post a Comment