Breaking News
Home / iOS / iOS Snippets / How to display a Dialog using UIAlertView in iOS?

How to display a Dialog using UIAlertView in iOS?

Snippet

The following utility method shows how to display a Dialog using UIAlertView.

  1. + (void) displayAlertOk: (NSString *) title andMessage: (NSString *) message {
  2. [self displayAlert: title andMessage: message forStatus: FALSE withCaption: @"OK"];
  3. }
  4.  
  5. + (void) displayAlertError: (NSString *) title andMessage: (NSString *) message {
  6. [self displayAlert: title andMessage: message forStatus: TRUE withCaption: @"Close"];
  7. }
  8.  
  9. (void) displayAlert: (NSString *) title andMessage: (NSString *) message forStatus: (BOOL) status withCaption: (NSString *) caption {
  10. // open a alert with an OK
  11. UIAlertView *dialog = [[UIAlertViewalloc] init];
  12. [dialog setDelegate: self];
  13. [dialog setTitle: title];
  14. [dialog setMessage: message];
  15. [dialog addButtonWithTitle: caption];
  16.  
  17.  
  18. UILabel *theBody = [dialog valueForKey: @"_bodyTextLabel"];
  19. if (status) {
  20. [theBody setTextColor:[UIColor redColor]];
  21. }
  22.  
  23. [dialog show];
  24. [dialog release];
  25.  
  26. }
[pb_builder]

Check Also

EKCalendar – That account does not allow calendars to be added or removed

Usecase When I am trying to create a new Calendar programmatically using the EventKit API …

Advertisment ad adsense adlogger