iCarousel无法加载图片

康西

因此,我正在尝试使用iCarousel以图像形式显示产品,然后用户可以简单地滚动并查看所有可用产品。

由于某些原因,当您加载视图控制器时,它根本不会显示任何图像,甚至不会显示轮播,它在我将其与int等数字一起使用之前就可以使用了。

我的代码如下:

ApparelViewController.m

#import "ApparelViewController.h"

@interface ApparelViewController ()

@property (nonatomic, strong) NSMutableArray *images;

@end

@implementation ApparelViewController

@synthesize carouselView = _carouselView;
@synthesize images = _images;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
    {
        //get image paths
        NSArray *imagePaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"Products"];

        //preload images (although FXImageView can actually do this for us on the fly)
        _images = [[NSMutableArray alloc] init];
        for (NSString *path in imagePaths)
        {
            [_images addObject:[UIImage imageWithContentsOfFile:path]];
        }
    }
    return self;
}

- (void)dealloc
{
    //it's a good idea to set these to nil here to avoid
    //sending messages to a deallocated viewcontroller
    _carouselView.delegate = nil;
    _carouselView.dataSource = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:236/255 green:240/255 blue:241/255 alpha:1];

    // Do any additional setup after loading the view.
    _carouselView.type = iCarouselTypeRotary;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    //free up memory by releasing subviews
    self.carouselView = nil;
}

- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [_images count];
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    if (view == nil)
    {
        FXImageView *imageView = [[FXImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.asynchronous = YES;
        imageView.reflectionScale = 0.5f;
        imageView.reflectionAlpha = 0.25f;
        imageView.reflectionGap = 10.0f;
        imageView.shadowOffset = CGSizeMake(0.0f, 2.0f);
        imageView.shadowBlur = 5.0f;
        imageView.cornerRadius = 10.0f;
        view = imageView;
    }
    //show placeholder
    ((FXImageView *)view).processedImage = [UIImage imageNamed:@"page.png"];

    ((FXImageView *)view).image = _images[index];

    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)goBack:(id)sender {

    NSString * storyboardName = @"Main";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
    UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"navBar"];
    [self presentViewController:vc animated:YES completion:nil];
}

@end

然后在ApparelViewController.h文件中,我有以下代码:

#import <UIKit/UIKit.h>
#import "iCarousel.h"
#import "FXImageView.h"

@interface ApparelViewController : UIViewController <iCarouselDelegate, iCarouselDelegate>

@property (strong, nonatomic) IBOutlet UIButton *backButton;
@property (strong, nonatomic) IBOutlet iCarousel *carouselView;

@end

真正令人烦恼的是,我以前曾经使用过iCarousel,但对于Swift来说,所以我知道它在那里的工作原理,但是我对Obj-C不太了解!

关于如何显示图像有什么想法吗?

JingJingTao

您可以检查的几件事,

  1. 检查“图像”是否在“ numberOfItemsInCarousel”中返回大于0的值,这很明显但值得检查。
  2. 检查是否实际加载了图像,即检查image [index]是否实际加载了图像。
  3. 我对FXImageView不太熟悉,但请尝试使用(void)setImage:(UIImage *)image;而不是Assigning @property (nonatomic, strong) UIImage *image;该文档说.image实际上并没有设置图像,而是添加了效果。

如果这些方法都不能解决您的问题,请发表评论,我会继续寻找,祝您好运。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法从网址显示图片到iCarousel

来自分类Dev

无法加载图片

来自分类Dev

图片无法加载(HTML)

来自分类Dev

HTML图片无法加载?

来自分类Dev

无法加载图片 HTTP

来自分类Dev

图片无法加载

来自分类Dev

无法加载图片

来自分类Dev

图片未加载-[无法加载给定的URL]

来自分类Dev

Django,无法加载图片,但已加载CSS

来自分类Dev

图片加载器无法加载我的实时图片网址

来自分类Dev

(HTML5)无法加载我的图片

来自分类Dev

无法将PNG图片加载为UIImage

来自分类Dev

Glide无法加载此类型的网址图片

来自分类Dev

TWTRTweetView无法加载个人资料图片

来自分类Dev

无法在Android中加载Facebook图片

来自分类Dev

Webpack无法加载背景图片

来自分类Dev

图片无法加载反应打字稿

来自分类Dev

Glide无法加载此类型的网址图片

来自分类Dev

网站-无法从服务器加载图片?

来自分类Dev

无法加载图片徽标+ SINTIA wordpress主题

来自分类Dev

Angular.js:图片无法加载

来自分类Dev

Google Chrome上的图片无法加载

来自分类Dev

图片无法在Phonegap上正确加载

来自分类Dev

网站图片无法加载-如何解决?

来自分类Dev

撰写推文图片无法加载?

来自分类Dev

图片无法加载(有时!)

来自分类Dev

Appcerator-Android 6图片无法加载

来自分类Dev

突然,图片无法在Wordpress中加载

来自分类Dev

Python PyQt5:无法加载图片