有一段时间后,有没有办法解雇一个无按钮UIalertView?

时间:2010-11-16 09:16:28

标签: ios objective-c uialertview dismiss

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"tittle"
               message:@""
                 delegate:self
              cancelButtonTitle:@""
              otherButtonTitles:nil];
  [alertView show];
  [alertView release];

我希望在alerview显示一段时间之后对其进行调整,但是当alertview没有按钮时,如果我调用了-dismissWithClickedButtonIndex:animated: method和 - performSelector:withObject:afterDelay:,它就无效 有没有其他方法可以解雇它? 谢谢你的任何想法!

4 个答案:

答案 0 :(得分:26)

-(void)xx  {
     [self performSelector:@selector(dismissAlertView:) withObject:alertView afterDelay:2];
}
-(void)dismissAlertView:(UIAlertView *)alertView{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}

就是它。我修复它

答案 1 :(得分:2)

使用10秒延迟解雇

 var line = svg.append("line")
              .attr("x1", function(){ return x(lineEnd)})
              .attr("x2", function(){ return x(lineEnd)})
              .attr("y1", 0)
              .attr("y2", height)
              .attr("stroke-width", 6)
              .attr("stroke", "black")
              .attr("stroke-dasharray", "8,8")



  line.append('text')
             .attr('class', 'barsEndlineText')
             .attr('text-anchor', 'middle')
              .attr("x", 0)
             .attr("y", ".35em")
             .text('I am label')

答案 2 :(得分:1)

在Xamarin.iOS / Monotouch中,这对我有用:

private async Task ShowToast(string message, UIAlertView toast = null)
    {
        if (null == toast)
        {
            toast = new UIAlertView(null, message, null, null, null);
            toast.Show();
            await Task.Delay(2000);
            await ShowToast(message, toast);
            return;
        }

        UIView.BeginAnimations("");
        toast.Alpha = 0;
        UIView.CommitAnimations();
        toast.DismissWithClickedButtonIndex(0, true);
    }

请记住,如果从后台线程(而不是主UI线程)调用异步方法,则仍然需要InvokeOnMainThread。 这只是意味着您调用上面的方法:

 BeginInvokeOnMainThread(() =>
 {
   ShowToast(message);
 });

答案 3 :(得分:0)

更新为上面的答案,UIAlertViewdeprecated Answer At this Link

第二个功能应该是这样的

-(void)dismissAlertView:(UIAlertController *)alertView{

  [alertView dismissViewControllerAnimated:YES completion:nil];
}