如何在警报视图中处理发件人标记

时间:2013-09-06 20:31:42

标签: ios5 uialertview

我是iOS开发的新手。我有另外一个开发人员完成的以下方法

-(IBAction)btnDelete:(UIButton *)sender
{
    indexOfBlockedFriend=sender.tag-50;
    [self deleteFriend];
}

我想在执行删除操作之前显示警报视图。我该怎么做。

2 个答案:

答案 0 :(得分:2)

要处理AlertView按钮单击,您必须符合UIAlertViewDelegate协议。 在your.h

@interface YourViewController:UIViewController<UIAlertViewDelegate>{
  .......
  .......
}

然后实现UIAlertViewDelegate协议方法, 在你的.m

- (void)alertView:(UIAlertView *)alertView 
                   clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0){
      //cancel clicked ...do your action
    }else if (buttonIndex == 1){
      //reset clicked
    }
}

答案 1 :(得分:1)

使用UIAlertView类

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello World" message:@"Hello" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];

如果您想拥有多个选项,则需要成为警报的委托才能获得触摸按钮的回调。委托是面向对象编程(OOP)的概念,您必须熟悉它。

编辑:

您可能对基于块的UIAlertViews感兴趣。我在很多项目中使用的那个叫做UIAlertView + MKBlockAdditions。它包含用于处理警报处理的块中的所有警报委托逻辑的简单方法。

相关问题