我定义了一个UIAlertView,它的标记= 101,确定是否保存,当单击保存按钮时显示另一个名为alertView2
的UIAlertView,然后删除rootView的子视图。但是当我在这里调用清除代码[self clearAllSubviewsInRootView];
时,在调用alertView2之前清除子视图。我如何解决它?如何在两个UIAlertView之间执行操作(ios7)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 101)
{
if (buttonIndex == 0)
{
}
else
{
if (buttonIndex == 1)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"input fileName" message:nil delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"OK", nil];
alertView.tag = 102;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
[self clearAllSubviewsInRootView];
}
}
if (alertView.tag == 102)
{
if (buttonIndex == 0)
{
}
else
{
NSArray *viewArray = [self.canvasView subviews];
NSUserDefaults *UD = [NSUserDefaults standardUserDefaults];
NSString *scaleStr = [UD objectForKey:@"scale"];
NSArray *dataArray = [NSArray arrayWithObjects:scaleStr, _labelArrivalTime.text, _textAccidentLocation.text,
_textDeclare.text, _textWeather.text, _textRoadSurface.text, [NSNumber numberWithFloat:canvasSize], nil];
NSMutableArray *array = [NSMutableArray arrayWithObjects:viewArray, dataArray, nil];
NSData * encodedata=[NSKeyedArchiver archivedDataWithRootObject:array];
NSString *fileName = [alertView textFieldAtIndex:0].text;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *floerName = @"file";
NSString *saveDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:floerName];
NSString *filePath = [saveDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.rta", fileName]];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:filePath])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"file existed" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alertView.tag = 103;
[alertView show];
}
else
{
[encodedata writeToFile:filePath atomically:YES];
[self saveImage:_prospector.image :filePath :@"勘查员"];
[self saveImage:_draftman.image :filePath :@"绘图员"];
[self saveImage:_person.image :filePath :@"当事人"];
}
}
}
}
虽然延迟应该可以解决问题(见我的回答如下),以我的经验延迟解决问题就像使用胶带固定你的汽车。它最终会脱落,并且不会阻止生长在...下面的锈... – auco