我目前有一个包含2行自定义单元格的UITableView.我最近在我的故事板上添加了第二个原型单元,并且一直试图将它添加到我的UITableView中但没有成功.我的cellForRowAtIndexPAth方法如下:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as FlightsDetailCell
cell.userInteractionEnabled = false
if indexPath.section == 0 {
cell.graphView.enableBezierCurve = true
cell.graphView.enableReferenceYAxisLines = true
cell.graphView.enableYAxisLabel = true
cell.graphView.colorYaxisLabel = UIColor.whiteColor()
cell.graphView.delegate = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDelegate
cell.graphView.dataSource = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDataSource
return cell
}
if indexPath.section == 1 {
cell.graphView.enableBezierCurve = true
cell.graphView.enableReferenceYAxisLines = true
cell.graphView.enableYAxisLabel = true
cell.graphView.colorYaxisLabel = UIColor.whiteColor()
cell.graphView.delegate = self
cell.graphView.dataSource = self
return cell
}
if indexPath.section …Run Code Online (Sandbox Code Playgroud) 我使用BEMSimpleLineGraph Pod创建了一个折线图,但是,就我而言,无法弄清楚为什么x-Axis标签没有出现在任何比iPhone 5更新的设备上.
编辑:我应该提到默认的enableXAxisLabel = YES.
以下是布置图表的代码:
#import "WeightChartCell.h"
@implementation WeightChartCell
@synthesize viewCell, arrayPlots, myGraph, labelWeightHistory;
- (void)awakeFromNib {
}
- (void)layoutSubviews {
[super layoutSubviews];
float width = viewCell.bounds.size.width;
self.myGraph = [[BEMSimpleLineGraphView alloc] initWithFrame:CGRectMake(-20, 40, width+20, 150.0)];
self.myGraph.dataSource = self;
self.myGraph.delegate = self;
self.myGraph.colorTop = [UIColor whiteColor];
self.myGraph.colorBottom = [UIColor colorWithRed:190/255.0 green:218/255.0 blue:246/255.0 alpha:1];
self.myGraph.colorLine = [UIColor colorWithRed:124/255.0 green:181/255.0 blue:236/255.0 alpha:1];
self.myGraph.colorPoint = [UIColor colorWithRed:124/255.0 green:181/255.0 blue:236/255.0 alpha:1];
self.myGraph.widthLine = 3;
self.myGraph.sizePoint = 10;
self.myGraph.alwaysDisplayDots = YES;
self.myGraph.colorXaxisLabel = [UIColor …Run Code Online (Sandbox Code Playgroud) 我正在配置我的BEMSimpleLineGraph并且除了线性渐变着色之外已经能够成功完成.在提供的示例Obj-C项目中引用此代码之后
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = {
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 0.0
};
self.myGraph.gradientBottom = CGGradientCreateWithColorComponents(colorspace, components, locations, num_locations);
Run Code Online (Sandbox Code Playgroud)
并在Swift中将其转录为此内容:
let colorspace:CGColorSpaceRef = CGColorSpaceCreateDeviceRGB()
let num_locations:size_t = 2
var locations: [CGFloat] = [0.0, 1.0]
var components: [CGFloat] = [
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 0.0
]
self.myGraph.gradientBottom = CGGradientCreateWithColorComponents(colorspace, components, locations, num_locations)
Run Code Online (Sandbox Code Playgroud)
一切都正确构建但引发包含的BEMLine.m文件中的EXC_BAD_ACCESS内存错误,在此行停止
CGContextDrawLinearGradient(ctx, self.bottomGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillBottom.bounds)), 0);
Run Code Online (Sandbox Code Playgroud)
我已经包含了obj-c桥接头,添加了CoreGraphics框架,在Storyboard中相应ViewController的属性窗格中启用了底色,引用了Apple的开发页面以确保所有参数的正确数据类型,但我仍然会变干.在检查错误相似性时,我也意识到尝试绘制顶部线性渐变也会出现同样的错误.错误似乎在于试图绘制渐变的Obj-C代码,但我再次无法做什么.
core-graphics objective-c linear-gradients swift bemsimplelinegraph
今晚在我的应用程序上工作时,我遇到了一个新的情况.我正在尝试将2个不同的图形[使用BEMSimpleLineGraph]分别加载到UITableView的不同行中.我创建了一个自定义单元格,其中包含一个继承自BEMSimpleLineGraphView的UIView.我的看法控制器自然地继承UIViewController,BEMSimpleLineGraphDelegate,BEMSimpleLineGraphDataSource,UITableViewDataSource,和UITableViewDelegate.
UITableViewDataSource和BEMSimpleLineGraphDataSource双方都需要的方法,但是当我宣布我的表视图的numberOfRowsInSection和方法的cellForRowAtIndexPath,我不能把我的numberOfPointsInLineGraph和valueForPointAtIndex方法的cellForRowAtIndexPath里面,因为这不符合BEMSimpleLineGraphDataSource要求.
这是我目前的课程:
import Foundation
class FlightsDetailViewController: UIViewController, BEMSimpleLineGraphDelegate, BEMSimpleLineGraphDataSource, UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as FlightsDetailCell
cell.userInteractionEnabled = false
cell.graphView.enableBezierCurve = true
cell.graphView.enableReferenceYAxisLines = true
cell.graphView.enableYAxisLabel = true
cell.graphView.colorYaxisLabel = UIColor.whiteColor()
cell.graphView.delegate = self
cell.graphView.dataSource = self
return cell
}
func lineGraph(graph: BEMSimpleLineGraphView!, …Run Code Online (Sandbox Code Playgroud) 我一直在使用BEMSimpleLineGraph 作为我最初为swift 2.3构建的项目,现在我将它迁移到swift 3所以在将库更新到版本4.1之后它给了我以下错误,它无法覆盖方法,因为它们是没有,但删除它说的方法
'ViewController'不符合协议'BEMSimpleLineGraphDataSource'
这可能听起来像一个奇怪的问题,但我正在尝试实现BEMSimpleLineGraph库来生成一些我在UITableView中放置的图形.我的问题是我如何引用外部dataSource和Delegate以在每个单元格中放置不同的图形(BEMSimpleLineGraph在UITableView和UICollectionView之后建模).我目前有这样的事情:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as FlightsDetailCell
cell.userInteractionEnabled = false
if indexPath.section == 0 {
cell.graphView.delegate = GroundspeedData()
cell.graphView.dataSource = GroundspeedData()
return cell
}
if indexPath.section == 1 {
cell.graphView.delegate = self
cell.graphView.dataSource = self
return cell
}
return cell
}
Run Code Online (Sandbox Code Playgroud)
第1部分的dataSource和Delegate在此下面正确设置,GroundspeedData类如下所示:
class GroundspeedData: UIViewController, BEMSimpleLineGraphDelegate, BEMSimpleLineGraphDataSource {
func lineGraph(graph: BEMSimpleLineGraphView!, valueForPointAtIndex index: Int) -> CGFloat {
let data = [1.0,2.0,3.0,2.0,0.0]
return CGFloat(data[index])
}
func numberOfPointsInLineGraph(graph: BEMSimpleLineGraphView!) -> …Run Code Online (Sandbox Code Playgroud)