我是一名初学者,正在学习并尝试使用Nick Lockwood的iCarousel。我打算将图片放在iCarousel中。以下是我的.m和.h代码:
//.m
@implementation ViewController
@synthesize images;
...
- (void)awakeFromNib
{
if (self) {
//set up carousel data
//wrap YES = infinite loop
wrap = YES;
self.images = [NSMutableArray arrayWithObjects:
@"apple.jpg",@"lemon.jpg",@"orange.jpg",@"melon.jpg",@"mango.jpg",nil];
}
}
- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
if (view == nil)
{
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[images objectAtIndex:index]]];
}
return view;
}
// .h
@interface ViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>{
NSMutableArray *images;
...
}
@property (nonatomic,retain) NSMutableArray *images;
…
@end
我打算添加30张图片,因此我希望代码易于维护。 我的问题是我想通过NSBundle或应用程序目录获取图像,我尝试了不同的代码,但图像未出现在旋转木马中。谢谢您的帮助。