我之前问过关于这个项目的另一个问题,Travis 非常有帮助。上一个问题
考虑到这个建议,我正在尝试为 C4Shape 类创建一个子类,我为 X 和 Y 位置值向该类添加了 2 个属性(均为浮点数)。我不只是调用 C4Shape 的 .center 属性的原因是因为要将它们添加到画布中,我更喜欢使用左上角而不是中心。
我正在尝试为这个新类编写自定义 Init 方法,但是出现错误。
这是我正在使用的自定义初始化代码:
自定义形状.m
- (id)initWithColor:(UIColor *)fillColor atX:(float)_xValue atY:(float)_yValue
{
CGRect frame = CGRectMake(_xValue, _yValue, 100, 100);
self = [customShape rect:frame];
self.lineWidth = 0.0f;
self.fillColor = fillColor;
self.xValue = _xValue;
self.yValue = _yValue;
return self;
}
C4WorkSpace.m
-(void)setup {
customShape *testShape = [[customShape alloc]initWithColor:[UIColor greenColor] atX:50.0f atY:50.0f];
[self.canvas addShape:testShape];
}
我怀疑罪魁祸首是self = [customShape rect:frame];
这是我看到的警告:“不兼容的指针类型从'C4Shape *'分配给'customeShape *_strong'”
当我尝试运行它时引发的实际错误是:“由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[C4Shape setXValue:]:无法识别的选择器发送到实例 0x9812580'”
和以前一样,我正在制作可以保存颜色值的按钮,当您点击该按钮时,它将发送一个带有该按钮 fillColor 以及 iPad IP 的 UDP 数据包。