gpt4 book ai didi

ios - 在不同的地方使用相同的 UIAlertView

转载 作者:行者123 更新时间:2023-11-29 10:46:26 24 4
gpt4 key购买 nike

我有一个 UIAlertView,alertView,它是在 viewDidLoad 方法中初始化的,例如:

self.alertView = [[UIAlertView alloc] initWithTitle:@"Meddelande"
message:@"Do you want to continue?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];

我还有一些通过按下不同按钮调用的方法:

- (IBAction)didPressButton1 {

[self.alertView show];
}

我以为这会显示 alertView,但没有任何反应。一种解决方案是调用一个方法来初始化 alertView 并同时显示它,但我希望它能工作。

alertView 的属性如下所示:

@property (nonatomic, strong) UIAlertView *alertView;

我还在类扩展中添加了委托(delegate),如下所示:

@interface MyViewController () <UIAlertViewDelegate>
@end

我做错了什么?

汉克

最佳答案

你没有做坏事。此代码有效。你的错误在于你如何声明你的 alertView

一定要这样做

@property (nonatomic, retain)UIAlertView *alertView;

并且您正在将您的 didPressButton1 方法连接到您的 UIButton

关于ios - 在不同的地方使用相同的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22199208/

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