Я хочу отображать несколько изображений в контроллере вида с помощью iCarousel.
iCarousel не показывает мои объекты изображения C
я перечислить все мои изображения в NSMutableArray фото,
, а затем я назвал массив фотографии в методе 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
Вы не настройки Делегирование iCarousel, ни DataSource к вашему ViewController. –
@TomKnapen: где я должен его установить? если он находится на доске объявлений, я уже установил его. в TestController.h, я тоже установил здесь свой код .h: TestController: UIViewController –
Shasapo
В таком случае вы не должны вызывать '[carousel reloadData]' (например, в вашем 'viewDidLoad')? –