I'm writing the exact same thing right now. My problem is that the segmented control is unclickable.
#import "DateLinePlotView.h"
@implementation DateLinePlotView
@synthesize xLabels;
@synthesize yValues;
@synthesize graphView;
- (id) init
{
if (self = [super init])
{
// Set up the graph view
self.graphView = [[S7GraphView alloc] initWithFrame: CGRectMake(-20, 60, 380, 300)];
self.graphView.dataSource = self;
[self addSubview: graphView];
self.xLabels = [[NSMutableArray alloc] init];
[xLabels addObject: @"One"];
[xLabels addObject: @"Two"];
[xLabels addObject: @"Three"];
self.yValues = [[NSMutableArray alloc] init];
[yValues addObject: [NSNumber numberWithInt: 3]];
[yValues addObject: [NSNumber numberWithInt: 8]];
[yValues addObject: [NSNumber numberWithInt: 3]];
// Set up the segment control
NSArray *segmentTextContent = [NSArray arrayWithObjects: @"All", @"Year", @"Month", nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.frame = CGRectMake( kLeftMargin,
340 + kTweenMargin + 20,
282,
kSegmentedControlHeight);
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 1;
segmentedControl.enabled = true;
[self addSubview:segmentedControl];
[segmentedControl release];
}
return self;
}
- (void)dealloc
{
[xLabels release];
[yValues release];
[graphView release];
[super dealloc];
}
#pragma mark -
#pragma mark S7GraphViewDataSource methods
- (NSUInteger)graphViewNumberOfPlots:(S7GraphView *)graphView
{
/* Return the number of plots you are going to have in the view. 1+ */
return 1;
}
- (NSArray *)graphViewXValues:(S7GraphView *)graphView
{
/* An array of objects that will be further formatted to be displayed on the X-axis.
The number of elements should be equal to the number of points you have for every plot. */
return xLabels;
}
- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex
{
/* Return the values for a specific graph. Each plot is meant to have equal number of points.
And this amount should be equal to the amount of elements you return from graphViewXValues: method. */
return yValues;
}
- (void)segmentAction:(id)sender
{
NSLog(@"segmentAction: selected segment = %d", [sender selectedSegmentIndex]);
}
@end