objective-c – Obj-C:委托方法未被调用
发布时间:2020-12-16 10:21:03 所属栏目:百科 来源:网络整理
导读:我是iOS Dev的新手,我正在关注2010年秋季的斯坦福CS193P课程.我正在完成作业3并且我将我的委托设置为我的视图并使用调试器我注意到对我的委托的调用方法不会发生,我不明白会发生什么.我的代码如下: GraphViewController.h: @interface GraphViewController
我是iOS Dev的新手,我正在关注2010年秋季的斯坦福CS193P课程.我正在完成作业3并且我将我的委托设置为我的视图并使用调试器我注意到对我的委托的调用方法不会发生,我不明白会发生什么.我的代码如下:
GraphViewController.h: @interface GraphViewController : UIViewController <GraphViewDelegate> { GraphView *graphView; float scale; } @property (retain) IBOutlet GraphView *graphView; @property float scale; - (IBAction)zoomIn; - (IBAction)zoomOut; @end GraphViewController.m: @implementation GraphViewController @synthesize graphView,scale; - (NSString *)functionForGraph:(GraphView *)requestor { NSLog(@"%@",@"culo peluo"); return @"lol"; } - (float)scaleForGraph:(GraphView *)requestor { return self.scale; } - (IBAction)zoomIn { } - (IBAction)zoomOut { } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)dealloc { [super dealloc]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data,images,etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.graphView.delegate = self; self.scale = 20; [self.graphView setNeedsDisplay]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end GraphView.h: @class GraphView; @protocol GraphViewDelegate - (NSString *)functionForGraph:(GraphView *)requestor; - (float)scaleForGraph:(GraphView *)requestor; @end @interface GraphView : UIView { id <GraphViewDelegate> delegate; } @property (assign) id <GraphViewDelegate> delegate; @end GraphView.m: @implementation GraphView @synthesize delegate; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (void)drawRect:(CGRect)rect { CGFloat cgScale = [self.delegate scaleForGraph:self]; [AxesDrawer drawAxesInRect:self.bounds originAtPoint:self.center scale:cgScale]; } - (void)dealloc { [super dealloc]; } @end 解决方法
>在设置图表视图委托的行上放置一个断点.
>检查graphView变量.它没有? 这种情况一直发生在我身上,并且总是(几乎总是如此),因为我无法将插座连接到界面构建器中的视图. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |