gpt4 book ai didi

objective-c - 没有任何按钮的 UIAlertView

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:07 25 4
gpt4 key购买 nike

我想知道下面的代码是否可以。我试图在 2 秒后(并且 alertView 中没有任何按钮)从“timedAlert”方法自动关闭 alertView。

    //this is in another method  
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Login successful." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
[alert release];
[self timedAlert];
}

-(void)timedAlert
{
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:2];
}

-(void)dismissAlert:(UIAlertView *) alertView
{
[alertView dismissWithClickedButtonIndex:nil animated:YES];
}

如果 alertView 的 cancelButton 设置为“nil”,“[alertView dismissWithClickedButtonIndex:0 animated:YES];”将如何处理?事情的工作???我尝试将 cancelButton 设置为“nil”并且它起作用了,但无法弄清楚如何......

P.S: 我从另一个调用 timedAlert 方法

感谢任何帮助!谢谢!

最佳答案

首先让我说如果你用自定义 View 处理这个会更好,但话虽如此,问题看起来出在

[alert release];

您在使用完对象之前就释放了它(我很惊讶它没有崩溃)。

做这样的事情

// other code
alert = [[UIAlertView alloc] initWithTitle:nil message:@"Login successful." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:3.0f];
}

-(void)dismissAlert:(UIAlertView *) alertView
{
[alertView dismissWithClickedButtonIndex:nil animated:YES];
[alertView release];
}

关于objective-c - 没有任何按钮的 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7486466/

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