【问题标题】:Run a method after subclass of UIAlertView gets dismissed在 UIAlertView 的子类被解除后运行一个方法
【发布时间】:2023-03-19 00:44:01
【问题描述】:

我使用 UIAlerView 子类创建自定义登录页面。现在,当我单击按钮时,它会打开 UIAlertView 我想根据按下的按钮更改主视图。

但是由于 UIAlerView 的所有实现都在另一个类中,尽管我更改了视图,但它不会保留它,因为该类变量没有得到它的值。

谁能帮我解决这个问题?如果需要,我可以发布代码。

谢谢你, 安基塔

【问题讨论】:

  • 两个类之间需要使用委托方法进行通信。
  • @Robin:你能告诉我如何在两个类之间使用委托方法吗?

标签: iphone objective-c xcode delegates uialertview


【解决方案1】:

您可以为 alertView 使用如下自定义的 init 方法,并将 _sender 存储在全局或类变量中。喜欢

身份证发件人; - (id)initWithSender:(id)_sender { self = [超级初始化]; 如果(自我){ 发件人=_发件人; } 回归自我; }

从 RootVC/bgview 初始化 alertView 如下并定义一个名为

-(void) alertIndexSelected:(NSInterger) 索引;

{

//根据选中的按钮改变背景视图 }

在 rootvc/你的主视图中。
 alertViewobj =[[alertView alloc] initWithSender:self];

当在 alertview 上选择按钮时,调用以下方法,这将通知您的 rootvc 有关按下了哪个警报索引。使用以下 alertview 委托。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { [发送者 alertIndexSelected: buttonIndex]; }

【讨论】:

    【解决方案2】:

    如果您打算使用委托方法,那么我认为您需要引用其中一些链接。

    How to use custom delegates in Objective-C

    How do I create delegates in Objective-C?

    http://iosdevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html

    我希望这对您理解代表有很大帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      相关资源
      最近更新 更多