gpt4 book ai didi

ios - 如何在 IOS 9 的 UIAlertController 中添加按钮

转载 作者:技术小花猫 更新时间:2023-10-29 10:41:25 27 4
gpt4 key购买 nike

我们如何在 iOS 9 中使用 UIAlertView 以及如何在 UIAlertController 中添加按钮

UIAlertController * alert=[UIAlertController 

alertControllerWithTitle:@"Title" message:@"Message"preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:@"Yes, please"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
**//What we write here????????**


}];
UIAlertAction* noButton = [UIAlertAction
actionWithTitle:@"No, thanks"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
**//What we write here????????**

}];

[alert addAction:yesButton];
[alert addAction:noButton];

[self presentViewController:alert animated:YES completion:nil];

最佳答案

UIAlertController * alert=[UIAlertController alertControllerWithTitle:@"Title"
message:@"Message"
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* yesButton = [UIAlertAction actionWithTitle:@"Yes, please"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
/** What we write here???????? **/
NSLog(@"you pressed Yes, please button");

// call method whatever u need
}];

UIAlertAction* noButton = [UIAlertAction actionWithTitle:@"No, thanks"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
/** What we write here???????? **/
NSLog(@"you pressed No, thanks button");
// call method whatever u need
}];

[alert addAction:yesButton];
[alert addAction:noButton];

[self presentViewController:alert animated:YES completion:nil];

迅速

let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
let yesButton = UIAlertAction(title: "Yes, please", style: .default, handler: {(_ action: UIAlertAction) -> Void in
/** What we write here???????? **/
print("you pressed Yes, please button")
// call method whatever u need
})
let noButton = UIAlertAction(title: "No, thanks", style: .default, handler: {(_ action: UIAlertAction) -> Void in
/** What we write here???????? **/
print("you pressed No, thanks button")
// call method whatever u need
})
alert.addAction(yesButton)
alert.addAction(noButton)
present(alert, animated: true) { _ in }

关于ios - 如何在 IOS 9 的 UIAlertController 中添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35152650/

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