【问题标题】:UIAlertView not fading even after the response action is taken即使在采取响应操作后,UIAlertView 也不会消失
【发布时间】:2011-12-10 08:01:44
【问题描述】:

在我的 UIAlertView 中,我想在按下“确定”按钮时打开另一个 UIView。

但问题是,即使在 UIView 显示后,警报仍保留在屏幕中,一旦消失,UIView 似乎已被禁用。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add details" message:@" Do you like to set the details now?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
[alert show];
[alert release];

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{   // the user clicked one of the OK/Cancel buttons
    NSString *title = [alertView title];

    if([title isEqualToString:@"Add details"])
    {
        .......

任何帮助将不胜感激!

【问题讨论】:

    标签: ios objective-c uialertview uialertviewdelegate


    【解决方案1】:

    为什么不检查委托方法中按下的按钮而不是标题? 也就是说,在

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0){
            // User pressed "YES"
        }else{
            // User pressed "NO"
        }
    }
    

    取消按钮的索引为 0,其他按钮的索引增加。为了检测这是哪个警报,您还应该给它一个标签。希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      可能是因为在实际关闭警报视图之前添加了新视图。所以最好使用 didDismissWithButtonIndex 委托来显示现有警报视图的按钮单击事件的新视图,而不是 clickedButtonAtIndex

      - (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
      {
      //Add the view
      }
      

      代替

      - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
      {
      //Add the view
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-06
        • 2020-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多