我正在尝试将自定义 UIViews(使用 Core Plot 绘制的图形)添加为 iCarousel 中的元素,但我没有看到正在绘制的图形。这是我的头文件:
@interface MTViewController : UIViewController <iCarouselDataSource, iCarouselDelegate,
CPTBarPlotDataSource, CPTBarPlotDelegate>
@property (strong, nonatomic) IBOutlet iCarousel *aCarousel;
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (nonatomic) BOOL wrap;
@property (strong, nonatomic) IBOutlet CPTGraphHostingView *graphView;
@property (nonatomic, retain) NSMutableArray *data;
@property (strong, nonatomic) NSMutableArray *animals;
@property (nonatomic, retain) CPTXYGraph *graph;
@property (strong, nonatomic) NSMutableArray *graphs;
@property (strong, nonatomic) NSMutableArray *descriptions;
@end
实现文件是:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//set up carousel data
wrap = NO;
self.graphs = [NSMutableArray arrayWithObjects: self.graphView,nil];
}
return self;
}
- (void)viewDidLoad
{
aCarousel.type = iCarouselTypeCoverFlow2;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setACarousel:nil];
[self setLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
#pragma - mark iCarousel Delegate
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [self.graphs count];
}
- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
// limit the number of item views loaded concurrently (for performance)
return 1;
}
- (CPTGraphHostingView*)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(CPTGraphHostingView *)view
{
// create a numbered view
// view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[animals objectAtIndex:index]]];
// return view;
CGSize size = self.graphView.frame.size;
float width = size.width;
CPTGraphHostingView *currentGraph ;
for (int i = 0; i < self.graphs.count; i++) {
CGRect frame;
frame.origin.x = width * i;
frame.origin.y = 0;
frame.size = size;
currentGraph = [graphs objectAtIndex:i];
currentGraph.frame = frame;
[self generateBarPlot:frame];
}
return currentGraph;
}
- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
return 1;
}
- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
// usually this should be slightly wider than the item views
return 240;
}
- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
return self.wrap;
}
- (void)carouselDidScroll:(iCarousel *)carousel
{
//[label setText:[NSString stringWithFormat:@"%@", [descriptions objectAtIndex:carousel.currentItemIndex]]];
[label setText:[NSString stringWithFormat:@"Testing"]];
}
....接着是生成图形的方法
任何帮助将不胜感激。
谢谢阅读。