Search code examples
iphoneobjective-cnsdictionaryuialertviewuserinfo

How to add userInfo to a UIAlertView?


I would like to know how to add a userInfo object, or any NSDictionary, to a UIAlertView?

Thank you.


Solution

  • If you are on > iOS 4.0 (for blocks) and you only want one or two buttons, you could use this category I made:

    https://github.com/rsaunders100/UIAlertView-Blocks

    It bypasses the need to add user info since you put your click handeling function straight into the alert. e.g.

     #import UIAlertView+Blocks.h
    
     ...
    
     ...
    
     NSString* myUserInfo = @"example";
    
     [UIAlertView displayAlertWithTitle:@"Example Alert View With Blocks"
                                message:nil
                        leftButtonTitle:@"Ok"
                      leftButtonAction:^{
                                          NSLog(@"%@", myUserInfo);
                                        } 
                      rightButtonTitle:nil
                     rightButtonAction:nil];