我有一种方法可以清除UITextFields
中的所有UIViewController
。
我有很多方法在发生之前触发该功能。我想要问用户使用UIAlertView
是否可以在操作发生之前清除字段。
我知道alertView:clickedButtonAtIndex:
但不想真正使用它,因为我的开关看起来像这样:
- (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
。
由于
答案 0 :(得分:-2)
@interface
//Keep a global references or repeated use...
@property(nonatomic, retain) UIAlertView *myAlertView;
@end
@implementation
-(void)alertViewCallingMethod
{
//Generate the alertView on the same handle for repeated use.
myAlertView = [[UIAlertView alloc] initWith..... ];
myAlertView.delegate = self;
[myAlertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView == myAlertView)
{
//do you stuff...
}
}
@end
这是关于我的答案的不必要的投票的补充:
问题提问者最后说了
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.
根据上述要求,我对这个问题的回答是最合适的。我给你的答案是,可以使用相同的HANDLE来重复使用alertView对象,然后转移删除标记单独的UIAlertView的所有不必要的检查,并为委托中的每个人写一个校验码。