Я новичок в iOS Dev, я слежу за классами Stanford CS193P на осень 2010 года. Я нахожусь на задании 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