从在线加载图像时的 UIActivityIndicatorView ?
我有一个简单的脚本,显示在来自互联网的 UIImageView 中。
有没有办法显示 UIActivityIndicatorView 或类似的东西来向用户显示它正在加载?
这是我的最小代码:
NSString *imagePath = [NSString stringWithFormat:@"urlofimagehere.jpg"];
NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imagePath]];
UIImage *myimage = [[UIImage alloc] initWithData:mydata];
[imageView setImage:myimage];
[myimage release];
谢谢! 库尔顿
编辑:代码已删除
I have a simple script that displays in a UIImageView from the internet.
Is there a way to display a UIActivityIndicatorView or something of that sort to show the user that it's loading?
Here's my minimal code:
NSString *imagePath = [NSString stringWithFormat:@"urlofimagehere.jpg"];
NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imagePath]];
UIImage *myimage = [[UIImage alloc] initWithData:mydata];
[imageView setImage:myimage];
[myimage release];
Thanks!
Coulton
EDIT: CODE REMOVED
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是一个同步方法。这意味着它将阻塞,直到数据通过网络加载。如果您希望能够保持 UI 响应能力,您将需要使用异步方法。有关更多信息,请阅读:http://akosma.com/2010 /05/28/initwithcontentsofurl-methods-considered-harmful/
我建议使用 NSURLRequest 和 NSURLRequestDelegate 在数据加载完成时接收回调。这是一个例子:
希望这有帮助!
is a synchronous method. This means it will block until the data is loaded over the network. If you want to be able to keep your UI responsive, you'll want to use an asynchronous approach. For more info, read this: http://akosma.com/2010/05/28/initwithcontentsofurl-methods-considered-harmful/
I'd recommend using NSURLRequest with an NSURLRequestDelegate to receive callbacks when the data is finished loading. Here's an example:
Hope this helps!