Ios UIAlertView设置消息不执行任何操作
我试图在UIAlertView中显示上载进度。我有一个带有AFHTTPClient服务器子类的API和一些代码,在这些代码中我向视图发送进度信息Ios UIAlertView设置消息不执行任何操作,ios,progress-bar,uialertview,Ios,Progress Bar,Uialertview,我试图在UIAlertView中显示上载进度。我有一个带有AFHTTPClient服务器子类的API和一些代码,在这些代码中我向视图发送进度信息 [operation setUploadProgressBlock:^(NSInteger bytesWritten,long long totalBytesWritten,long long totalBytesExpectedToWrite) { float progress = totalBytesWritten / (float)t
[operation setUploadProgressBlock:^(NSInteger bytesWritten,long long totalBytesWritten,long long totalBytesExpectedToWrite)
{
float progress = totalBytesWritten / (float)totalBytesExpectedToWrite;
request *svc = [[request alloc] init];
[svc setProgress:[NSNumber numberWithFloat:progress]];
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
当上传过程开始时,我在视图中创建UIAlertView
API文件
if (uploadFile) {
[formData appendPartWithFileData:uploadFile name:@"file" fileName:@"photo.jpg" mimeType:@"image/jpeg"];
request *svcAlert = [[request alloc] init];
[svcAlert showProgressAlert];
}
查看文件
- (void) showProgressAlert{
progressBarAlert = [[UIAlertView alloc] initWithTitle: @"Идет загрузка"
message: @"0"
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
progressView = [[UIProgressView alloc] initWithProgressViewStyle: UIProgressViewStyleBar];
progressView.frame = CGRectMake (20, 20, 50, 30);
[progressBarAlert addSubview:progressView];
[progressBarAlert show];
}
然后在我看来,我也试图用setMessage更改UIAlertView消息参数,但什么也没发生。ProgressView不会显示在AlertView中,即使我使用addSubview添加它
-(void) setProgress: (NSNumber *) progress {
progressView.progress = [progress floatValue];
//progressBarAlert.message = [NSString stringWithFormat:@"%@", progress];
[progressBarAlert setMessage:[NSMutableString stringWithFormat:@"Загрузка %@", progress]];
}
最后一个问题是,如何在不按取消按钮的情况下关闭UIAlertView
此外,我尝试将子视图添加到我的视图中,而不是使用alertView,但应用程序因未捕获异常而崩溃。也许有人能给我一些关于这项任务的建议。我会让你参考苹果公司的文档,特别是关于 UIAlertView类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不能修改
通过执行
[progressBarAlert addSubview:progressView]尝试执行的操作
是不允许的,它将使您的应用程序在Apple审查过程中被拒绝。在iOS7addSubview中:
从不在UIView
上调用super,因此实际上不做任何事情。所以我不建议你这么做。但是,您可以使用自定义警报视图来获取所需信息。请注意,iOS 7.thx不再支持向UIAlertView
添加任何子视图。我将不使用子视图,但如果setMessage可以工作,则可以