gpt4 book ai didi

iphone - iphone sdk 4.3 中按钮点击的警报消息

转载 作者:行者123 更新时间:2023-12-03 18:37:21 25 4
gpt4 key购买 nike

我是xcode编程初学者,请告诉我如何在xcode-iphone-4.3中单击按钮时显示警报消息

我的代码如下,

- (IBAction)buttonPressed:(id)sender{

UIAlertView* mes=[[UIAlertView alloc] initWithTitle:@"Hello World!!!!!!"
message:@"This is the Iphone app" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];

[mes show];

[mes release];

请帮我解决这个问题。

最佳答案

-(IBAction)buttonOnePressed:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Clicked button 1"
message: @"Alert Message here"
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];

[alert setTag:1];
[alert show];
}

-(IBAction)buttonTwoPressed:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Clicked button 2"
message: @"Alert Message here"
delegate: self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];

[alert setTag:2];
[alert show];
}

下面是跟踪 Alertview 上哪个按钮被点击的委托(delegate)方法。

  -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex   
{
if (alertView.tag == 1) { // UIAlertView with tag 1 detected
if (buttonIndex == 0)
{
NSLog(@"user pressed Button Indexed 0");
// Any action can be performed here
}
else
{
NSLog(@"user pressed Button Indexed 1");
// Any action can be performed here
}
}

else if (alertView.tag == 2) { // UIAlertView with tag 2 detected
if (buttonIndex == 0)
{
NSLog(@"user pressed Button Indexed 0");
// Any action can be performed here
}
else
{
NSLog(@"user pressed Button Indexed 1");
// Any action can be performed here
}
}
}

如果您有多个 UIAlertView,并且可以确定在其委托(delegate)中单击了哪个 UIAlertView 按钮,您可以将标记设置为 UIAlertView方法 clickedButtonAtIndex 使用其各自的标签。

关于iphone - iphone sdk 4.3 中按钮点击的警报消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8906127/

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