0

I have small problem, it looks like thread can sort it, but I'm not good in threads, I read many tutorials, but still didn't get idea how to sort it. Scenario is: I am saving file to Amazon s3, and it's working perfect, but i decide before uploading the file to amazon, give for user to enter file name, and when i call UIAlertView class, program keep running, and saving file as @"test.txt". Here is a part of the code:

fileNmae = @"test.txt";
fileName = [self getFileName];
NSLog(@"File name is %@", fileName);

/// -----------------------------------
/// Uploading file to Amazon cloud !!!!
/// -----------------------------------
...

and here alert method:

-(NSString*) getFileName {

     // some alert method

return @"someFile.name";
}

Thanks

4

3 回答 3

0

当用户按下 OK 时,getFileName 将调用 alert 并调用其 delegete 方法。在 .m 中实现 alertView 的委托为

@interface ViewController :UIViewController<UIAlertViewDelegate>

回调方法是

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    /// -----------------------------------
    /// Uploading file to Amazon cloud !!!!  Once user press OK on alert upload will start
    /// ----------
}
于 2013-05-15T12:48:52.283 回答
0

你这样做的方式无法实现这一点。实现它的方法是先制作警报视图并获取文件名,然后再进行上传

fileNmae = @"test.txt";
  1. 在此显示警报视图之后
  2. 在其委托 clickedButton... 您可以获取文件名,然后从那里上传文件

对于带有文本的警报视图

UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"Title" message:@"Please enter someth" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
av.alertViewStyle = UIAlertViewStylePlainTextInput;
[av textFieldAtIndex:0].delegate = self;
[av show];

实现文本字段的委托方法以及警报

于 2013-05-15T12:55:46.593 回答
0

这里不需要线程。实现UIAlertViewDelegate方法并将上传任务放入

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // Uploading file to Amazon cloud !!!!
}
于 2013-05-15T12:47:09.223 回答