gpt4 book ai didi

ios - 向 AlertView 发送参数

转载 作者:行者123 更新时间:2023-12-01 17:43:19 24 4
gpt4 key购买 nike

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

所以,我所拥有的是

被调用的委托(delegate)方法:

- (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 标签
    属性(property)。
     myAlertView.tag  = YOUR_INT;
  • According to the documentation,

    Note : The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

    So please use the 3rd method only if you are not intending to submit app to app store. Thanks user soemarko ridwan for the tip.



    对于传递复杂对象,子类 UIAlertView,添加一个对象
    属性(property)
    @interface CustomAlertView : UIAlertView
    @property (nonatomic, retain) id object;
    @end

    @implementation CustomAlertView
    @synthesize object;
    - (void)dealloc {
    [object release];
    [super dealloc];
    }
    @end

    当你创建 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]);
    }
  • 关于ios - 向 AlertView 发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13047527/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com