1

こんにちは私は検索して検索し、それをここに投稿することにしました-この質問はあなたにはばかげているかもしれませんが、それはすでに1日かかります:(

だから私は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:終了が呼び出されて例外がスローされます

「[_MyPieChartssetDelegate:self];」の行とPO self._MyPieCharts.delegateにブレークポイントを設定すると、次のようになります。

po self.MyPieCharts.delegateエラー:実行が中断されました。理由:無効なObjCオブジェクトを逆参照するか、認識されないセレクターを送信しようとしました。プロセスは実行前の状態に戻りました。

スクリーンショットを投稿できないので、ここにプロジェクトをアップロードしました。

これは、self.MyPieCharts.delegateが初期化されていないことを意味しますか?どうしたらいいか分かりますか?

どうもありがとう!

4

2 に答える 2

2

MyPieChartsがInterfaceBuilderに接続されていないようです。

于 2012-10-16T14:49:41.347 に答える
0

デリゲートを次のように設定してみてください:

[_MyPieCharts setDelegate:XYPieChartDelegate];
于 2012-10-16T08:58:02.490 に答える