ios - 如何使用 SDWebImage
<p><p>我有 <code>UITableViewCell</code> 并在此加载图像,所以我想加载图像并显示激活指示器。这次图像加载时间非常长,所有图像在图像显示在表格 View 后加载。很多时候图像无法加载并且用户 UIInterface 挂起。并且不要在应用程序中处理任何进程。我很累,我使用了 <code>SDWebImage</code> 库。请帮助如何可能,谢谢</p>
<pre><code>#import "UIImageView+WebCache.h"
@interface pictureViewController ()
{
NSArray*picarray;
NSArray*titlearray;
NSArray*idarray;
}
@end
@implementation pictureViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = ;
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
;
[[ navigationBar] setTitleTextAttributes:@{NSForegroundColorAttributeName: }];
[ setBackgroundImage: forBarMetrics:UIBarMetricsDefault];
_tableview.separatorColor = ;
NSURLRequest *req=[initWithURL:];
response =[init];
;
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
;
NSLog(@"error receving data %@",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
//NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = ;
// NSLog(@"response data %@",json);
NSArray *results = ;
picarray = ;
titlearray = ;
// NSLog(@"my title is%@",titlearray);
idarray=;
//NSLog(@"my galary id is%@",idarray);
;
}
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning
{
;
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"tableview cell");
picture_viewcontrollerCell *cell = ;
if (cell==nil)
{
NSArray *nib = [ loadNibNamed:@"Cell" owner:self options:nil];
cell = ;
}
//NSData* imageData = [ initWithContentsOfURL:]];
// UIImage* image = [ initWithData:imageData];
//cell.picture.image =image;
cell.titlelbl.text=];
NSURL*url= [valueForKey:@"img_url"];
;
];
returncell;
}
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你应该试试这个(显示activityIndicator & Load Image using <strong>SDWebImage</strong>)-</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"tableview cell");
picture_viewcontrollerCell *cell = ;
if (cell==nil)
{
NSArray *nib = [ loadNibNamed:@"Cell" owner:self options:nil];
cell = ;
}
cell.titlelbl.text=];
NSURL*url= ]];
;
;
;
options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
returncell;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何使用 SDWebImage,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38368133/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38368133/
</a>
</p>
页:
[1]