问题描述
SGView
(下面)中的一个circleOfButtons:buttonSize:radius:
函数是从ParentView
和我调用的每当 ParentView
向 SGView
发送消息时,希望 ParentView
定义 SGView
内的值.
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
.
这是实现文件.
#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 将多个 UIButton 排列成一个圆圈,本质上是这样的
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
错误消息 - 在 SGView *myView
行 - 是:
The error message - at the line SGView *myView
- is:
没有已知的选择器类方法'circleOfButtons:buttonSize:radius:'
我的猜测是编译器想要在接口中声明.我正在研究这些教程,试图决定界面文件应该是什么样子,尽管有6 个可能已经回答了我的问题的 SO 问题,只有 这个 有一个似乎不太相关的例子.
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.
这是我的接口文件.
#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.
更新
这里是SGView.h
(修改)
#import <UIKit/UIKit.h>
@interface SGView : UIView {
}
+(id)circleOfButtons:(int)buttonCount buttonSize:(CGFloat)buttonSize circleRadius:(CGFloat)circleRadius;
@end
我也注意到如果声明
SGView *myView = [SGView circleOfButtons:count buttonSize:size radius:radius];
改为
SGView *myView = [self circleOfButtons:count buttonSize:size radius:radius];
错误更改为
ParentView"没有可见的@interface 声明了选择器circleOfButtons:buttonSize:radius:"
以前是
选择器 'circleOfButtons:buttonSize:radius:' 没有已知的类方法
推荐答案
您正在致电
SGView *myView = [SGView circleOfButtons:count buttonSize:size radius:radius];
应该是
SGView *myView = [SGView circleOfButtons:count buttonSize:size circleRadius:radius];
这篇关于选择器 'circleOfButtons:buttonSize:radius:' 没有已知的类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!