How do you pass a variable to the UIAlertView delegate?

前端 未结 6 1352
刺人心
刺人心 2020-12-28 16:22

How do you pass a variable to the UIAlertView delegate?

I have a variable that I want to use in the alert view delegate. It is only used in the functio

6条回答
  •  忘掉有多难
    2020-12-28 17:10

    UIAlertView is a subclass of UIView which has a tag property you can set to an integer. Unfortunately if you need something other than an integer to identify/pass info to the delegate than you will need to set some properties (or set up an array with the tag indexing into it) on the delegate itself. Advaith's way will probably work but is technically not supported by Apple.

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Are you sure?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];        
        [alert setAlertViewStyle:UIAlertViewStyleDefault];  
        alert.tag = SOMEINTEGER;
        [alert show];
    

提交回复
热议问题