嗨,我已经搜索和搜索,然后我决定在这里发布 - 这个问题对你来说可能很愚蠢,但它已经花了我一天的时间:(
所以我正在尝试使用 XYPieChart 来绘制一些饼图,这里有一些来自 XYPieChart 的代码:
XYPieChart.h
@class XYPieChart;
@protocol XYPieChartDataSource <NSObject>
@required
- (NSUInteger)numberOfSlicesInPieChart:(XYPieChart *)pieChart;
- (CGFloat)pieChart:(XYPieChart *)pieChart valueForSliceAtIndex:(NSUInteger)index;
@optional
- (UIColor *)pieChart:(XYPieChart *)pieChart colorForSliceAtIndex:(NSUInteger)index;
- (NSString *)pieChart:(XYPieChart *)pieChart textForSliceAtIndex:(NSUInteger)index;
@end
@protocol XYPieChartDelegate <NSObject>
@optional
- (void)pieChart:(XYPieChart *)pieChart willSelectSliceAtIndex:(NSUInteger)index;
- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index;
- (void)pieChart:(XYPieChart *)pieChart willDeselectSliceAtIndex:(NSUInteger)index;
- (void)pieChart:(XYPieChart *)pieChart didDeselectSliceAtIndex:(NSUInteger)index;
@end
XYPieChart.m
@synthesize dataSource = _dataSource;
@synthesize delegate = _delegate;
然后在我自己的视图控制器 XYPieChartViewTestViewController.h
#import <UIKit/UIKit.h>
#import "XYPieChart.h"
@interface XYPieChartViewTestViewController : UIViewController <XYPieChartDelegate, XYPieChartDataSource>
@property (weak, nonatomic) IBOutlet XYPieChart *MyPieCharts;
@end
和 XYPieChartViewTestViewController.m
#import "XYPieChartViewTestViewController.h"
@interface XYPieChartViewTestViewController ()
@end
@implementation XYPieChartViewTestViewController
@synthesize MyPieCharts = _MyPieCharts;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_MyPieCharts setDelegate:self];
}
但是在执行 [_MyPieCharts setDelegate:self]; 时,有一个转储:
2012-10-16 10:33:53.100 XYPieChartViewTest[3859:11303]-[UIView setDelegate:]:无法识别的选择器发送到实例 0x9040680 *第一次抛出调用堆栈:libc++abi.dylib:终止调用抛出异常
如果我在“[_MyPieCharts setDelegate:self];”行和 PO self._MyPieCharts.delegate 处放置一个断点,它会说:
po self.MyPieCharts.delegate 错误:执行被中断,原因:尝试取消引用无效的 ObjC 对象或向其发送无法识别的选择器。进程已恢复到执行前的状态。
我已经在这里上传了项目,因为我无法发布屏幕截图。
这是否意味着 self.MyPieCharts.delegate 未初始化?你知道我该怎么做吗?
非常感谢!