我正在使用i carousel在coverflow中加载一堆图像,但我没有得到它?..最初我有Signal sigabart问题..之后我编辑了一些代码,视图显示...我错过了什么?...
#import "CollectionViewController.h"
@interface CollectionViewController ()
@property (nonatomic, retain) NSMutableArray *items;
@end
@implementation CollectionViewController
@synthesize carousel;
@synthesize items;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
[items release];
[carousel release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [items count];
}
- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
return 29;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
view = [NSArray arrayWithObjects:[UIImage imageNamed:@"gal1.jpg"],
[UIImage imageNamed:@"gal2.jpg"],
[UIImage imageNamed:@"gal3.jpg"],
[UIImage imageNamed:@"gal5.jpg"],
[UIImage imageNamed:@"gal6.jpg"],
[UIImage imageNamed:@"gal7.jpg"],
[UIImage imageNamed:@"gal8.jpg"],
[UIImage imageNamed:@"gal9.jpg"],
[UIImage imageNamed:@"gal10.jpg"],
[UIImage imageNamed:@"gal11.jpg"],
[UIImage imageNamed:@"gal12.jpg"],
[UIImage imageNamed:@"gal13.jpg"],
[UIImage imageNamed:@"gal14.jpg"],
[UIImage imageNamed:@"gal15.jpg"],
[UIImage imageNamed:@"gal16.jpg"],
[UIImage imageNamed:@"gal17.jpg"],
[UIImage imageNamed:@"gal18.jpg"],
[UIImage imageNamed:@"gal19.jpg"],
[UIImage imageNamed:@"gal20.jpg"],
[UIImage imageNamed:@"gal21.jpg"],
[UIImage imageNamed:@"gal22.jpg"],
[UIImage imageNamed:@"gal23.jpg"],
[UIImage imageNamed:@"gal24.jpg"],
[UIImage imageNamed:@"gal25.jpg"],
[UIImage imageNamed:@"gal26.jpg"],
[UIImage imageNamed:@"gal27.jpg"],
[UIImage imageNamed:@"gal28.jpg"],
}
else {
}
return view;
}
@end
在模拟器上运行时我只是得到屏幕而不是图像?...我被困在这里......
答案 0 :(得分:1)
我已经这样做了。 试试这个:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//set up carousel data
wrap = NO;
self.items = [NSArray arrayWithObjects:[UIImage imageNamed:@"gal1.jpg"],
[UIImage imageNamed:@"gal2.jpg"],
[UIImage imageNamed:@"gal3.jpg"],
[UIImage imageNamed:@"gal5.jpg"],
[UIImage imageNamed:@"gal6.jpg"],
[UIImage imageNamed:@"gal7.jpg"],
[UIImage imageNamed:@"gal8.jpg"],
[UIImage imageNamed:@"gal9.jpg"],
[UIImage imageNamed:@"gal10.jpg"],
[UIImage imageNamed:@"gal11.jpg"],
[UIImage imageNamed:@"gal12.jpg"],
[UIImage imageNamed:@"gal13.jpg"],
[UIImage imageNamed:@"gal14.jpg"],
[UIImage imageNamed:@"gal15.jpg"],
[UIImage imageNamed:@"gal16.jpg"],
[UIImage imageNamed:@"gal17.jpg"],
[UIImage imageNamed:@"gal18.jpg"],
[UIImage imageNamed:@"gal19.jpg"],
[UIImage imageNamed:@"gal20.jpg"],
[UIImage imageNamed:@"gal21.jpg"],
[UIImage imageNamed:@"gal22.jpg"],
[UIImage imageNamed:@"gal23.jpg"],
[UIImage imageNamed:@"gal24.jpg"],
[UIImage imageNamed:@"gal25.jpg"],
[UIImage imageNamed:@"gal26.jpg"],
[UIImage imageNamed:@"gal27.jpg"],
[UIImage imageNamed:@"gal28.jpg"],nil];
}
return self;
}
然后在你的:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[items objectAtIndex:index]]];
return view;
}
哦,还有另一个,请善意编辑你的numberOfVisibleItemsInCarousel
并将其设置为return 7;
,这样就不会浪费内存,我想。
答案 1 :(得分:1)
iCarousel工作代码:
委托方法:
- (UIView *)carousel:(__unused iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
if (view == nil){
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 400 , 600)];
((UIImageView *)view).image = [UIImage imageNamed:[imageCarosualArray objectAtIndex:index]];
view.contentMode = UIViewContentModeCenter;
[view.layer setMasksToBounds:YES];
}
return view;
}
数组中的多个图像
CarosualArray =[[NSMutableArray alloc]initWithObjects:@"test1.png",@"test2.png",@"test3.png",@"test4.png",@"test5.png",@"test6.png",@"test7.png",@"test8.png",@"test9.png", nil];