i implemented core plot in xcode
. i'm trying insert legend in cell
. here code of how implemented legend
.
- (void)configurelegend { cptgraph *graph = self.hostview.hostedgraph; cptlegend *thelegend = [cptlegend legendwithgraph:graph]; // configure legend thelegend.numberofcolumns = 1; thelegend.fill = [cptfill fillwithcolor:[cptcolor whitecolor]]; thelegend.borderlinestyle = [cptlinestyle linestyle]; thelegend.cornerradius = 5.0; // add legend graph graph.legend = thelegend; graph.legendanchor = cptrectanchorright; cgfloat legendpadding = - (self.chartview.bounds.size.width / 8); graph.legenddisplacement = cgpointmake(legendpadding, 0.0);
here tried:
uitableviewcell *cell = [self.tableview cellforrowatindexpath:[nsindexpath indexpathforrow:2 insection:0]]; [cell addsubview:thelegend]; }
i following error:
incompatible pointer types sending 'cptgraph *' parameter of type 'uiview *'
i understand error, , did wrong. question is, how can add legend
subview
of cell?
edit
here i'm talking about:
i want move part has info - "aapl" goog" "msft" (the thing on right), cell.
as error message suggests, you're trying add object isn't of type uiview
subview cell. add ctpgraph object instance of type cptgraphhostingview
, add subview cell:
cptgraphhostingview *hostingview = [[cptgraphhostingview alloc] initwithframe:frame]; hostingview.hostedgraph = graph; [cell addsubview:hostingview];
furthermore, shouldn't accessing cells that. should adding graph subview uitableview's delegate method, tableview:cellforrowatindexpath:
. use method retrieve legend , add cell before returning completed cell.
updated - you're using static uitableview, implementation of cellforrowatindexpath:
differs slightly. have retrieve cell super
(the table view) instead of dequeuing reusable cell:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [super tableview:tableview cellforrowatindexpath:indexpath]; ...retrieve instance of graph... cptgraphhostingview *hostingview = [[cptgraphhostingview alloc] initwithframe:frame]; hostingview.hostedgraph = graph; [cell addsubview:hostingview]; return cell; }
update 2 - add legend cell:
[cell.layer addsublayer:graph.legend];
update 3 - text upside down because coordinate system used legend's layer may different. can fix rotating layer 180 degrees using transform:
legendlayer.transform = catransform3dmakerotation(m_pi / 180.0f, 0, 1, 0);