2014-03-05 81 views
0

我想在用户在IPhone应用程序中触摸按钮时弹出一个简单的消息窗口。我用UIAlertView中的类,在执行这样的代码:IOS UIAlertView未显示

-(IBAction)sendMessage:(UIButton *)sender 

{ 
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"test message" 
                 message:@"test" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 


    [alert show]; 
} 

我也挂的sendMessage方法动作里面润色。

什么也没有显示。

有什么想法吗?我是iOS编程新手。 感谢您的帮助。

+0

使用断点,以确保'[警报显示]'被调用 –

+0

是的,从一般的调试,例如断点,是一个良好的开端。但是这个问题需要更多的信息才能得到正确的回答。初始者的IB连接镜头。 –

+1

如果调用'sendMessage'并且应用程序没有崩溃,那么'[alert show];'几乎肯定会被调用。我的猜测是'sendMessage'实际上没有被调用。 – nhgrif

回答

1

您需要的按钮在你的情节提要/ XIB文件链接到功能或致电或代码

[button addTarget:self action:@selector(sendMessage:) forControlEvents:UIControlEventTouchUpInside]; 
1

我建议两件事设置它,给它一个尝试:

1)将delegate设置为self

2)尝试使IBAction参数类型为id。然后从“接口”构建器中删除并重新连接。

事情是这样的:

-(IBAction)sendMessage:(id)sender 

{ 
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"test message" 
                 message:@"test" 
                 delegate:self 
               cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 


    [alert show]; 
} 
+0

对不起我的错误,我连接了错误的按钮触摸动作,现在修复它并且工作正常。希望你不介意,谢谢.. – sparky

1
NSString* messageString = [NSString stringWithFormat: @"\"%@ \"does not apppear to be valid email address.Do You Want sent Anyway?", email]; 

      UIAlertView *alertView =[[UIAlertView alloc]initWithTitle:@"Invalid adress" message:messageString delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 
      [alertView show];