[CorePlot] add plot to Table View Cell

180 views
Skip to first unread message

Tobe

unread,
Apr 19, 2010, 10:29:58 AM4/19/10
to coreplot-discuss
Hi,
I want to add a plot to the cell of a table view. The UIViewController
uses:
CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view;
hostingView.hostedLayer = graph;
to put the graph on the view.
The xib file just includes one view of class CPLayerHostingView.

In cellForRowAtIndexPath I'm trying to add this view controller as a
subview to the cell:
PlotViewController *plotViewController = [[PlotViewController
alloc] initWithNibName:@"PlotView" bundle:nil];
[cellPlot.contentView addSubview:plotViewController.view];
[plotViewController release];
but I get the error:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -
[UIGroupTableViewCellDrawnBackground numberOfRecordsForPlot:]:
unrecognized selector sent to instance

--
You received this message because you are subscribed to the Google Groups "coreplot-discuss" group.
To post to this group, send email to coreplot...@googlegroups.com.
To unsubscribe from this group, send email to coreplot-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coreplot-discuss?hl=en.

Tobe

unread,
Apr 19, 2010, 10:32:48 AM4/19/10
to coreplot-discuss
i forgot to say that the error is in: [cellPlot.contentView
addSubview:plotViewController.view];

Drew McCormack

unread,
Apr 20, 2010, 2:57:22 AM4/20/10
to coreplot...@googlegroups.com
What might be happening is that the delegate of the CPGraph is not set properly. Make sure it is. It may even be set to the superview when you add the subview, not sure.

Another option would be just to create images for your plots offscreen, and add them to a UIImageView in each cell. Otherwise performance may be a problem.

Drew

Tobe

unread,
Apr 20, 2010, 10:53:02 AM4/20/10
to coreplot-discuss
i didn't set the delegate for graph at all. Didn't find anything in
the examples or here how to do it.

vj Kal

unread,
Apr 20, 2010, 1:53:00 PM4/20/10
to coreplot...@googlegroups.com
Look at this link:
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html
I used Subclassing UITableViewCell section to model my app and it works.

(1) I created an cellView calss which extended UITableViewCell
>>@interface ChartCell : UITableViewCell

(2) Created a CellView ChartCellView which extended UIView
and added to this the hosting view in initWithFrame method

hostingView = [[CPLayerHostingView alloc] initWithFrame:CGRectZero];
hostingView.frame = self.bounds;
hostingView.autoresizesSubviews = YES;
hostingView.autoresizingMask =
UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleLeftMargin;


[self addSubview:hostingView];


(3) Added the chartCellview in initWithStyle of UITableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier {

if (self = [super initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:reuseIdentifier]) {
CGRect chartFrame = CGRectMake(0.0, 0.0,
self.contentView.bounds.size.width,
self.contentView.bounds.size.height);
chartCellView = [[ChartCellView alloc] initWithFrame:chartFrame];
chartCellView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
[self.contentView addSubview:chartCellView];
}
return self;
}


Thanks,
vJ

Tobe

unread,
Apr 21, 2010, 5:24:52 AM4/21/10
to coreplot-discuss
yeah, that's working, so I can create my graph in the CellView. But
the current situation is, that I already have a graph in another view
for fullscreen view and just want to display a thumbnail in the cell.
I tried to init the fullscreen view and referenced the hostingView of
it to the hostingView in the cell, but then it always just displays
nothing.

On 20 Apr., 19:53, vj Kal <loc...@gmail.com> wrote:
> Look at this link:http://developer.apple.com/iphone/library/documentation/UserExperienc...
> I used Subclassing UITableViewCell section to model my app and it works.
>
> (1) I created an cellView calss which extended UITableViewCell
>
> >>@interface ChartCell : UITableViewCell
>
> (2) Created a CellView ChartCellView which extended UIView
> and added to this the hosting view in initWithFrame method
>
>        hostingView = [[CPLayerHostingView alloc] initWithFrame:CGRectZero];
>         hostingView.frame = self.bounds;
>         hostingView.autoresizesSubviews = YES;
>         hostingView.autoresizingMask =
> UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAuto resizingFlexibleRightMargin|UIViewAutoresizingFlexibleLeftMargin;

Drew McCormack

unread,
Apr 21, 2010, 6:10:37 AM4/21/10
to coreplot...@googlegroups.com
If you just want a thumbnail, I would simply use an offscreen graph to generate a PNG image. See the CPGraph class for a method to get the PNG. Note you might need to call layoutIfNeeded on the graph to get it to update before getting the PNG.

Drew

Tobe

unread,
Apr 21, 2010, 6:55:21 AM4/21/10
to coreplot-discuss
i created a method in my graph implementation which return a
CPNativeImage:
-(CPNativeImage *)loadImage {
[graph layoutIfNeeded];
CPNativeImage *image = [graph imageOfLayer];
return image;
}
but imageOfLayer returns (null). I create the graph and everything in
viewDidLoad(). Do I have to call it somehow before to create the
graph?

vj Kal

unread,
Apr 21, 2010, 11:09:29 AM4/21/10
to coreplot...@googlegroups.com
Hi Tobe,
I am not 100% sure about it but an offscreen image may be best and I
think its not recommended(not sure) to load another ViewControllers
view to another ViewController
Thanks,
Vijay
Reply all
Reply to author
Forward
0 new messages