2016-07-15 123 views
0

因此,我试图使用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那么好!

关于如何去显示图像的任何想法?

回答

1

你可以检查有几件事情,

  1. 检查“图像”是返回比“numberOfItemsInCarousel” 0伟大的,很明显,但值得一试的值。
  2. 检查图像是否实际加载,即检查图像[index]实际加载图像。
  3. 我并不熟悉FXImageView,但尝试使用(void)setImage:(UIImage *)image;而不是分配@property (nonatomic, strong) UIImage *image;。该文件说,.image实际上不设置图像,但添加效果。

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

+0

我已经尝试了很多东西,包括你的建议和运气:(有没有机会,也许你可以尝试使用iCarousel创建一个项目,看看你是否可以得到它显示不同的图像请 – Konsy

+0

我不知道不介意走开,也许我们可以继续聊聊吧?来这个房间,http://chat.stackoverflow.com/rooms/26424/iosandroidchaosoverflow – JingJingTao

+0

加入房间 – Konsy