Ios 将参数发送到AlertView

Ios 将参数发送到AlertView,ios,parameters,uialertview,Ios,Parameters,Uialertview,我有一个委托,它接收一条消息,删除一个作为参数的项。 我想显示确认AlertView,然后,如果用户按Yes,我想删除它 所以,我得到的是 被调用的委托方法: - (void) deleteRecording:aRecording(Recording*)aRecording { NSLog(@"Cancel recording extended view"); UIAlertView *alert = [[UIAlertView alloc]

我有一个委托,它接收一条消息,删除一个作为参数的项。 我想显示确认AlertView,然后,如果用户按Yes,我想删除它

所以,我得到的是

被调用的委托方法:

- (void) deleteRecording:aRecording(Recording*)aRecording {

     NSLog(@"Cancel recording extended view");
     UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle: NSLocalizedString(@"Cancel recording",nil)
                      message: NSLocalizedString(@"Are you sure you want to cancel the recording?",nil)
                      delegate: self
                      cancelButtonTitle: NSLocalizedString(@"No",nil)
                      otherButtonTitles: NSLocalizedString(@"Yes",nil), nil];
    [alert show];
    [alert release];

}
以及检查按下哪个按钮的方法:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    switch (buttonIndex) {
        case 0:
        {
            NSLog(@"Delete was cancelled by the user");
        }
        break;

        case 1:
        {

            NSLog(@"Delete deleted by user");
        }


    }

}
所以,我的问题是,如何将aRecording参数从第一个方法发送到第二个方法

非常感谢

  • 将该变量存储在成员变量中(最简单的解决方案)
  • 如果只传递int变量,则可以设置AlertView标记 财产

     myAlertView.tag  = YOUR_INT;
    
  • 据报道,

    注意:UIAlertView类旨在按原样使用,不支持子类化。此类的视图层次结构为 私有的 而且不能修改

    因此,请仅在您不打算提交时使用第三种方法 应用到应用商店。感谢用户soemarko ridwan提供的提示

    为了传递复杂对象,子类UIAlertView添加一个对象 财产

    创建AlertView时

     CustomAlertView *alert = [[CustomAlertView alloc]
                      initWithTitle: NSLocalizedString(@"Cancel recording",nil)
                      message: NSLocalizedString(@"Are you sure you want to cancel the recording?",nil)
                      delegate: self
                      cancelButtonTitle: NSLocalizedString(@"No",nil)
                      otherButtonTitles: NSLocalizedString(@"Yes",nil), nil];
    [alert setObject:YOUR_OBJECT];
    [alert show];
    [alert release];
    
    在代表中

    - (void)alertView:(TDAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
         NSLog(@"%@", [alertView object]);
    }
    
  • 将该变量存储在成员变量中(最简单的解决方案)
  • 如果只传递int变量,则可以设置AlertView标记 财产

     myAlertView.tag  = YOUR_INT;
    
  • 据报道,

    注意:UIAlertView类旨在按原样使用,不支持子类化。此类的视图层次结构为 私有的 而且不能修改

    因此,请仅在您不打算提交时使用第三种方法 应用到应用商店。感谢用户soemarko ridwan提供的提示

    为了传递复杂对象,子类UIAlertView添加一个对象 财产

    创建AlertView时

     CustomAlertView *alert = [[CustomAlertView alloc]
                      initWithTitle: NSLocalizedString(@"Cancel recording",nil)
                      message: NSLocalizedString(@"Are you sure you want to cancel the recording?",nil)
                      delegate: self
                      cancelButtonTitle: NSLocalizedString(@"No",nil)
                      otherButtonTitles: NSLocalizedString(@"Yes",nil), nil];
    [alert setObject:YOUR_OBJECT];
    [alert show];
    [alert release];
    
    在代表中

    - (void)alertView:(TDAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
         NSLog(@"%@", [alertView object]);
    }
    

  • +1.总结得好。至于2)——你也可以将自定义对象与警报关联起来,但是我会认为它是黑客的…3)一个不应该子类UIActuvVIEW。根据:UIAlertView类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不能修改。@soemarkoridwan感谢您的提示。。我把它添加到答案中。。不知怎的,以前从来没有读过。好的总结。至于2)——你也可以将自定义对象与警报关联起来,但是我会认为它是黑客的…3)一个不应该子类UIActuvVIEW。根据:UIAlertView类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不能修改。@soemarkoridwan感谢您的提示。。我把它添加到答案中。。不知怎的,以前从未读过。。