Several UIAlertViews for a delegate

前端 未结 5 824
-上瘾入骨i
-上瘾入骨i 2020-12-13 13:21

Currently I\'ve got a class popping up UIAlertViews here and there. Currently, the same class is the delegate for these (it\'s very logical that it would be). U

5条回答
  •  粉色の甜心
    2020-12-13 13:41

    Tag the UIAlertViews like this:

    #define kAlertViewOne 1
    #define kAlertViewTwo 2
    
    UIAlertView *alertView1 = [[UIAlertView alloc] init...
    alertView1.tag = kAlertViewOne;
    
    UIAlertView *alertView2 = [[UIAlertView alloc] init...
    alertView2.tag = kAlertViewTwo;
    

    and then differentiate between them in the delegate methods using these tags:

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        if(alertView.tag == kAlertViewOne) {
            // ...
        } else if(alertView.tag == kAlertViewTwo) {
            // ...
        }
    }
    

提交回复
热议问题