gpt4 book ai didi

ios - iCarousel 不会加载图像

转载 作者:行者123 更新时间:2023-11-29 00:48:19 24 4
gpt4 key购买 nike

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

出于某种原因,当您加载 viewcontroller 时,它根本不显示任何图像,甚至不显示轮播,它在我将它与数字 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. 检查“images”在“numberOfItemsInCarousel”中返回一个大于 0 的值,这很明显但值得检查。
  2. 检查图像是否实际加载,即检查 image[index] 是否实际加载图像。
  3. 我不太熟悉 FXImageView,但尝试使用 (void)setImage:(UIImage *)image; 而不是分配 @property (nonatomic, strong) UIImage *image; 。文档说 .image 实际上并没有设置图像,而是添加了效果。

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

关于ios - iCarousel 不会加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38398003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com