一遍又一遍地重复UIAlert代码

时间:2012-05-17 18:08:59

标签: objective-c xcode

我有这段代码:

-(IBAction)action2:(id)sender{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm" message:@"If you press of a new group with the name you have set will be created" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: @"Ok", nil];
[alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

if([title isEqualToString:@"Ok"])
{

    NSString *destDir = [NSString stringWithFormat:@"/sandbox/%@/", namegroup.text];

    NSString *filename5 = namegroup.text;
    NSString *filename6 = @"group";
    NSString *filename7 = @"groupdata";

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,       NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *getImagePath5 = [documentsDirectory stringByAppendingPathComponent:   [NSString stringWithFormat:@"%@", filename7]];

    NSMutableArray *titles = [NSMutableArray array];
    [titles addObject:filename5];

    NSMutableArray *keys = [NSMutableArray array];
    [keys addObject:filename6];

    NSDictionary *dict = [NSDictionary dictionaryWithObjects:titles forKeys:keys];

    NSString *jsonString = [dict JSONRepresentation];
    NSData *jsonData = [jsonString dataUsingEncoding: NSUTF8StringEncoding];

    [jsonData writeToFile: getImagePath5 atomically: YES];

    [[self restClient] uploadFile:filename7 toPath:destDir
                    withParentRev:nil fromPath:getImagePath5];

}

}

如果按下“确定”按钮,代码会一遍又一遍地重复。我怎么能只重复一次?

1 个答案:

答案 0 :(得分:0)

我发现有另一个具有相同取消标题的警报,当按下它时,它重新启动了相同的代码。谢谢你的帮助。

相关问题