gpt4 book ai didi

ios - UIAlertView 没有响应按钮事件

转载 作者:行者123 更新时间:2023-11-28 18:20:54 27 4
gpt4 key购买 nike

第一次使用 UIAlertViews 时,我不明白为什么它不起作用。当我单击任一按钮时,警报关闭,但没有 NSLog 输出。我究竟做错了什么?我想不通。谢谢!

.h

@interface LoginViewController : UIViewController <UIAlertViewDelegate>

@end

.m

- (IBAction)resetPassword:(UIButton *)sender {

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Password Reset"
message:@"A temporary password will be sent to you at the address we have on file."
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Reset Password", nil];
[alert show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) NSLog(@"button 0");
if (buttonIndex == 1) NSLog(@"button 1");
}

最佳答案

看来您从未在 UIAlertView 上设置委托(delegate)。应该是:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Password Reset"
message:@"A temporary password will be sent to you at the address we have on file."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Reset Password", nil];

这样 UIAlertView 就可以在用户点击按钮时调用您的方法,- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

关于ios - UIAlertView 没有响应按钮事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20895250/

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