作者:雷神白中凌 | 来源:互联网 | 2023-06-08 17:31
I am having a bit of a problem here, I am let the user upload some video to the server however I am having some difficulties managing a view that I am using to illustrate its progress, I know why the problem is happening and i found a way around it (sort of) here my problem
我在这里遇到了一些问题,我让用户将一些视频上传到服务器但是我在管理我用来说明其进展的视图时遇到一些困难,我知道为什么问题发生了,我发现了绕过它的方式(有点)我的问题
So if one tries to make some code that looks something like this (in a UIViewController
所以,如果有人试图制作一些看起来像这样的代码(在UIViewController中)
-(void)uploadMovie
{
UIActivityView indicator=new...
[self.view addSubview:indicator]
[uploader UploadMyMovie:data]
}
This code wont work, the uploader will lock the controller and will not allow time for the indicator to come on screen in time, i found waiting for a few seconds before calling the uploader works but i took another approach.
这段代码不起作用,上传器将锁定控制器并且不会让指示器及时进入屏幕的时间,我发现在调用上传器工作之前等了几秒钟,但我采取了另一种方法。
The approach was to start a new thread for the uploader and have a protocol in which the uploader object informs the UIViewController (or some delegate) when it starts uploading, its progress, and when it finishes uploading. Something like
方法是为上传器启动一个新线程,并有一个协议,上传者对象在开始上传,进度以及完成上传时通知UIViewController(或某个委托)。就像是
-(void)uploadMovie
{
UIActivityView indicator=new...
[self.view addSubview:indicator]
NSThread *thread=...
[thread start]
}
the delegate methods look something like this
委托方法看起来像这样
#pragma mark UploadProgressDelegate
-(void)didStartUploading
{
progressLabel= [[UILabel alloc] initWithFrame:CGRectMake(93, 240, 116, 32)];
ind= [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
ind.center=self.view.center;
[progressLabel setTextColor:[UIColor blackColor]];
[progressLabel setText:@"TEST"];
[self.view addSubview:progressLabel];
[self.view addSubview:ind];
[ind startAnimating];
[self.view bringSubviewToFront:progressLabel];
[ind setHidesWhenStopped:TRUE];
[self.view setUserInteractionEnabled:FALSE];
}
-(void)progressUpdate:(NSString*)progress
{
[progressLabel setText:progress];
}
-(void)didEndUploading;
{
[progressLabel removeFromSuperview];
[ind stopAnimating];
[ind removeFromSuperview];
[progressLabel release];
[ind release];
[self.view setUserInteractionEnabled:TRUE];
}
This works great and the indicator shows and everything, then i decided to let the user see the progress by adding a UILabel (reflected in the code above), howeverr for this the solution does not work, the label does not display and ofcourse no updates...
这很好用,指示器显示和所有内容,然后我决定让用户通过添加UILabel(反映在上面的代码中)看到进度,但是对于此解决方案不起作用,标签不显示且当然没有更新...
I was wondering if anyone has encounter this situation and has come up with a solution for it? or if you can possibly see from the code above why the label isnt showing...
我想知道是否有人遇到过这种情况并提出了解决方案吗?或者,如果你可以从上面的代码中看到为什么标签没有显示......
Thanks
2 个解决方案