问题
A function circleOfButtons:buttonSize:radius: in SGView (below) is called from ParentView and I want ParentView to define the values inside SGView whenever ParentView sends a message to SGView.
This is the implementation file.
#import <UIKit/UIKit.h>
#import “ParentView.h"
#import "SGView.h"
@implementation ParentView : UIView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:[UIScreen mainScreen].bounds];
if (self) {
self.backgroundColor = [UIColor lightGrayColor];
int count = 5;
CGFloat size = 80.0;
CGFloat radius = 68;
SGView *myView = [SGView circleOfButtons:count buttonSize:size radius:radius];
[self addSubview:myView];
}
return self;
}
SGView arranges multiple UIButtons in a circle and is essentially like this
#import "SGView.h"
@implementation SGView : UIView
+(id)circleOfButtons:(int)buttonCount buttonSize:(CGFloat)buttonSize circleRadius:(CGFloat)circleRadius
{
UIView *multipleViews = [self new];
// … circular geometry …
[multipleViews addSubview:circleButton];
}
return multipleViews;
}
@end
The error message - at the line SGView *myView - is:
No known class method for selector 'circleOfButtons:buttonSize:radius:'
My guess is the compiler wants a declaration in the interface. I’m working through these tutorials trying to decide what the interface file should look like and though there are 6 SO questions that may already have answered my question, only this one had an example that seemed vaguely relevant.
This is my interface file.
#import <UIKit/UIKit.h>
#import "ViewController.h"
#import "SGView.h"
@interface ParentView : UIView {
}
+(id)circleOfButtons:(int)buttonCount buttonSize:(CGFloat)buttonSize circleRadius:(CGFloat)circleRadius;
@end
Can anyone please give an example showing what this interface file should look like ? Thanks.
UPDATE
Here is SGView.h (revised)
#import <UIKit/UIKit.h>
@interface SGView : UIView {
}
+(id)circleOfButtons:(int)buttonCount buttonSize:(CGFloat)buttonSize circleRadius:(CGFloat)circleRadius;
@end
I also noticed if the statement
SGView *myView = [SGView circleOfButtons:count buttonSize:size radius:radius];
is changed to
SGView *myView = [self circleOfButtons:count buttonSize:size radius:radius];
the error changes to
No visible @interface for 'ParentView' declares the selector 'circleOfButtons:buttonSize:radius:'
it was previously
No known class method for selector 'circleOfButtons:buttonSize:radius:'
回答1:
You are calling
SGView *myView = [SGView circleOfButtons:count buttonSize:size radius:radius];
It should be
SGView *myView = [SGView circleOfButtons:count buttonSize:size circleRadius:radius];
回答2:
Declare +(id)circleOfButtons:(int)buttonCount buttonSize:(CGFloat)buttonSize circleRadius:(CGFloat)circleRadius in SGView.h file.
Now you will get the method in ParentView class.
Happy coding :) .
来源:https://stackoverflow.com/questions/43138769/no-known-class-method-for-selector-circleofbuttonsbuttonsizeradius