gpt4 book ai didi

ios - iCarousel 不显示我的图像 Objective-C

转载 作者:行者123 更新时间:2023-11-29 12:02:18 25 4
gpt4 key购买 nike

我想使用 iCarousel 在 View Controller 中显示多个图像。

我在 NSMutableArray foto 中列出我所有的图像,
然后我在 iCarousel 方法 viewForItemAtIndex 中调用数组照片。

我已经按照一些教程进行操作,但仍然无法正常工作。请帮我。

这是我的.m代码

#import "TestController.h"

@interface TestController () <UIActionSheetDelegate>

@property (nonatomic, retain) NSMutableArray *foto;


@end


@implementation TestController


@synthesize carousel;
@synthesize foto;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
foto = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Seleb1.jpg"],
[UIImage imageNamed:@"Seleb2.jpg"],
[UIImage imageNamed:@"Seleb3.jpg"],
nil];
}
return self;
}

- (void)dealloc
{

carousel.delegate = nil;
carousel.dataSource = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;

}

- (void)viewDidUnload
{
[super viewDidUnload];

self.carousel = nil;
}


#pragma mark -
#pragma mark iCarousel methods

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [foto count];
}



- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[foto objectAtIndex:index]]];
return view;
}

@end

有人可以帮助我吗?我的代码有什么问题?

更新代码

#import "TestController.h"

@interface TestController ()

@property (nonatomic, retain) NSArray *foto;


@end


@implementation TestController


@synthesize carousel;
@synthesize foto;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
foto = [NSArray arrayWithObjects:
@"Seleb1.jpg",
@"Seleb2.jpg",
@"Seleb3.jpg",
nil];
}
return self;

}

- (void)dealloc
{

carousel.delegate = nil;
carousel.dataSource = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
[carousel reloadData];
}

- (void)viewDidUnload
{
[super viewDidUnload];

self.carousel = nil;

}


#pragma mark -
#pragma mark iCarousel methods

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [foto count];
}


- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {

view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; // set the frame for your Image

UIImage *image = [UIImage imageNamed:[foto objectAtIndex:index]];
((UIImageView *)view).image = image;

return view;

}

- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display

return value+0.1;
}

@end

最佳答案

改变这一行

 view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[foto objectAtIndex:index]]];

Reason : you have already defined your array as [UIImage imageNamed:@"Seleb1.jpg"] , so in here you need call directly like

view = [[UIImageView alloc] initWithImage:[foto objectAtIndex:index]];

选择 2

创建一个数组

  foto = [NSArray arrayWithObjects:
@"Seleb1.jpg",
@"Seleb2.jpg",
@"Seleb3.jpg",
nil];

然后调用

 view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[foto objectAtIndex:index]]];

如果你需要

用这个

- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
[carousel reloadData];
}

更新答案

  - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {

view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; // set the frame for your Image

UIImage *image = [UIImage imageNamed:[foto objectAtIndex:index]];
((UIImageView *)view).image = image;

return view;

}

关于ios - iCarousel 不显示我的图像 Objective-C ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419462/

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