Ios 使用相同的UIAlertVIew和不同的方法清除字段

Ios 使用相同的UIAlertVIew和不同的方法清除字段,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我有一个方法可以清除UIViewController中的所有UITextFields。 我有很多方法可以在函数发生之前触发它。我想使用UIAlertView询问用户在操作发生之前是否可以清除字段。 我知道alertView:ClickedButtonIndex:,但我并不真的想使用它,因为我的开关看起来像这样: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

我有一个方法可以清除
UIViewController
中的所有
UITextFields
。 我有很多方法可以在函数发生之前触发它。我想使用
UIAlertView
询问用户在操作发生之前是否可以清除字段。 我知道
alertView:ClickedButtonIndex:
,但我并不真的想使用它,因为我的开关看起来像这样:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 2000)
    {
        if (buttonIndex == 0)
        {
          // do stuff
        }
        else if (buttonIndex == 1)
        {
            // do stuff
        }
    }
    if(alertView.tag == 3000)
    {
        if (buttonIndex == 0)
        {
          // do stuff
        }
        else if (buttonIndex == 1)
        {
            // do stuff
        }
    }
etc..
我正在寻找一种优雅的方法,在每个需要在触发之前清除屏幕的函数之前触发相同的
UIAlertView

谢谢

这是对我的回答未经表决而投反对票的补充:

提问者最后说

I'm searching for an elegant way to trigger the same UIAlertView before every function that needs to clear the screen before it's triggered.

根据上述要求,我对这个问题的回答是最恰当的。我给您的答案可以使用相同的句柄重复使用alertView对象,这将删除标记单独UIAlertView的所有不必要的检查,并在代理中为每个UIAlertView写一个检查代码。

如果您否决我的答案,那么至少写下原因。我的答案对一个程序员来说是足够正确的。这里的新手请不要不必要地投反对票。你之所以被投反对票,是因为你的答案与问题无关,加上你有一个我写的我不想做的事情的例子。程序员,请再次尝试阅读问题。在对我的问题进行降级投票之前,请在此处写下您自己的答案。您可以根据标题使用if-else:if([alert.title isEqualToString:@“Error”]){//do things here};
I'm searching for an elegant way to trigger the same UIAlertView before every function that needs to clear the screen before it's triggered.