iOS开发笔记--异步加载图片在TableView中的应用

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //AsyncImageView.h文件  
  2. @interface AsyncImageView : UIView {  
  3. NSURLConnection* connection;  
  4. NSMutableData* data;  
  5. }  
  6. @end  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //AsyncImageView.m文件  
  2. @implementation AsyncImageView  
  3.    
  4. - (void)loadImageFromURL:(NSURL*)url {  
  5. if (connection!=nil) { [connection release]; }  
  6. if (data!=nil) { [data release]; }  
  7. NSURLRequest* request = [NSURLRequest requestWithURL:url  
  8. cachePolicy:NSURLRequestUseProtocolCachePolicy  
  9. timeoutInterval:60.0];  
  10. connection = [[NSURLConnection alloc]  
  11. initWithRequest:request delegate:self];  
  12. //TODO error handling, what if connection is nil?  
  13. }  
  14.    
  15. - (void)connection:(NSURLConnection *)theConnection  
  16. didReceiveData:(NSData *)incrementalData {  
  17. if (data==nil) {  
  18. data =  
  19. [[NSMutableData alloc] initWithCapacity:2048];  
  20. }  
  21. [data appendData:incrementalData];  
  22. }  
  23.    
  24. - (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {  
  25.    
  26. [connection release];  
  27. connection=nil;  
  28.    
  29. if ([[self subviews] count]>0) {  
  30. [[[self subviews] objectAtIndex:0] removeFromSuperview];  
  31. }  
  32.    
  33. UIImageView* imageView = [[[UIImageView alloc] initWithImage:[UIImage imageWithData:data]] autorelease];  
  34.    
  35. imageView.contentMode = UIViewContentModeScaleAspectFit;  
  36. imageView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth || UIViewAutoresizingFlexibleHeight );  
  37.    
  38. [self addSubview:imageView];  
  39. imageView.frame = self.bounds;  
  40. [imageView setNeedsLayout];  
  41. [self setNeedsLayout];  
  42. [data release];  
  43. data=nil;  
  44. }  
  45.    
  46. - (UIImage*) image {  
  47. UIImageView* iv = [[self subviews] objectAtIndex:0];  
  48. return [iv image];  
  49. }  
  50.    
  51. - (void)dealloc {  
  52. [connection cancel];  
  53. [connection release];  
  54. [data release];  
  55. [super dealloc];  
  56. }  
  57.    
  58. @end  


[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //在tableview中具体使用  
  2. - (UITableViewCell *)tableView:(UITableView *)tableView  
  3. cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
  4.    
  5. static NSString *CellIdentifier = @"ImageCell";  
  6. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
  7.    
  8. if (cell == nil) {  
  9. cell = [[[UITableViewCell alloc]  
  10. initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]  
  11. autorelease];  
  12. else {  
  13. AsyncImageView* oldImage = (AsyncImageView*)  
  14. [cell.contentView viewWithTag:999];  
  15. [oldImage removeFromSuperview];  
  16. }  
  17.    
  18. CGRect frame;  
  19. frame.size.width=75; frame.size.height=75;  
  20. frame.origin.x=0; frame.origin.y=0;  
  21. AsyncImageView* asyncImage = [[[AsyncImageView alloc]  
  22. initWithFrame:frame] autorelease];  
  23. asyncImage.tag = 999;  
  24. NSURL* url = [imageDownload  
  25. thumbnailURLAtIndex:indexPath.row];  
  26. [asyncImage loadImageFromURL:url];  
  27.    
  28. [cell.contentView addSubview:asyncImage];  
  29.    
  30. return cell;  
  31. }  

转自: http://blog.sina.com.cn/s/blog_7f7a975b01017szx.html
内容概要:本文详细介绍了使用COMSOL进行三相电力变压器温度场与流体场耦合计算的具体步骤和技术要点。首先讨论了变压器温升问题的重要性和现有仿真与实测数据之间的偏差,接着阐述了电磁--流三场耦合建模的难点及其解决方法。文中提供了关键的材料属性设置代码,如变压器油的密度和粘度随温度变化的关系表达式,并强调了网格划分、求解器配置以及后处理阶段需要注意的技术细节。此外,还分享了一些实用的经验和技巧,例如采用分离式步进求解策略、优化网格划分方式等,确保模型能够顺利收敛并获得精确的结果。最后,作者推荐了几种常用的湍流模型,并给出了具体的参数设置建议。 适用人群:从事电力系统设计、变压器制造及相关领域的工程师和技术人员,特别是那些希望深入了解COMSOL软件在复杂多物理场耦合计算方面应用的人群。 使用场景及目标:适用于需要对变压器内部温度分布和油流情况进行精确模拟的研究或工程项目。主要目的是提高仿真精度,使仿真结果更加贴近实际情况,从而指导产品设计和优化运行参数。 其他说明:文中不仅包含了详细的理论解释和技术指导,还提供了一些实际案例供读者参考。对于初学者来说,可以从简单的单相变压器开始练习,逐步掌握复杂的三相变压器建模技能。同时,作者提醒读者要注意单位的一致性和材料属性的准确性,这是避免许多常见错误的关键所在。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值