I have implemented delete functionality in cocoa application now i want to show one meesage box when user click on delete button.
+2
A:
Take a look at NSAlert
, which has a synchronous -runModal
method:
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Hi there."];
[alert runModal];
As Peter mentions, a better alternative is to use the alert as a modal sheet on the window, e.g.:
[alert beginSheetModalForWindow:window
modalDelegate:self
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
Buttons can be added via -addButtonWithTitle:
:
[a addButtonWithTitle:@"First"];
[a addButtonWithTitle:@"Second"];
The return code tells you which button was pressed:
- (void) alertDidEnd:(NSAlert *)a returnCode:(NSInteger)rc contextInfo:(void *)ci {
switch(rc) {
case NSAlertFirstButtonReturn:
// "First" pressed
break;
case NSAlertSecondButtonReturn:
// "Second" pressed
break;
// ...
}
}
Georg Fritzsche
2010-05-27 09:27:23
Even better, begin the alert as a sheet on the window that contains the delete button. This way, the user can continue to use any other windows in your application.
Peter Hosey
2010-05-27 10:05:13
Wow its working fine.But how to put more buttons in this alert and how to get that buttons events
mikede
2010-05-27 10:33:09
@mik: By using [`-addButtonWithTitle:`](http://developer.apple.com/mac/library/documentation/cocoa/conceptual/Dialog/Tasks/UsingAlerts.html). There is also a [special on alerts](http://developer.apple.com/mac/library/documentation/cocoa/conceptual/Dialog/Tasks/UsingAlerts.html) in the docs that should help you.
Georg Fritzsche
2010-05-27 10:59:00