我正在使用旋转木马在 coverflow 中加载一堆图像,但我没有得到它?..最初我遇到了 Signal sigabart 问题..在我编辑了一些代码后, View 显示了...我错过了吗东西?...
#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
在模拟器上运行时,我只看到屏幕而不是图像?...我被困在这里...
最佳答案
我已经这样做了。 这里试试这个:
- (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;
这样就不会浪费内存了,我认为。
关于iphone - 如何使用此代码在 iCarousel 中加载多个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11247655/