0

我对 iOS 开发非常陌生。我有另一个开发人员完成的以下方法

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

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

4

2 回答 2

2

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

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

然后在 your.m 中实现 UIAlertViewDelegate 协议方法

- (void)alertView:(UIAlertView *)alertView 
                   clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0){
      //cancel clicked ...do your action
    }else if (buttonIndex == 1){
      //reset clicked
    }
}
于 2013-09-06T20:35:24.023 回答
1

使用 UIAlertView 类

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

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

编辑:

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

于 2013-09-06T20:36:03.920 回答