Objective c CGFloat中的错误消息
我是记分板应用程序,我不需要在点击按钮时添加UItextfield和标签。我在这些方法中不断出现错误。有什么建议吗 错误消息: “从不兼容的类型'double'分配到'UIView*'” 错误消息: “从不兼容的类型'UIView*'分配'CGFloat'(也称为'float')” 错误消息: “二进制表达式('UIView*'和'CGFloat'(也称为'float')的操作数无效” 代码如下:Objective c CGFloat中的错误消息,objective-c,Objective C,我是记分板应用程序,我不需要在点击按钮时添加UItextfield和标签。我在这些方法中不断出现错误。有什么建议吗 错误消息: “从不兼容的类型'double'分配到'UIView*'” 错误消息: “从不兼容的类型'UIView*'分配'CGFloat'(也称为'float')” 错误消息: “二进制表达式('UIView*'和'CGFloat'(也称为'float')的操作数无效” 代码如下: -(void)addPlayerTapped:(id)sender { NSLog(@"
-(void)addPlayerTapped:(id)sender {
NSLog(@"Adding Player");
self.yOffset = 60.0;
UIViewController *llVC = [[DetailViewController alloc] init];
llVC.view.alpha = 0.0;
[self.playersArray addObject:llVC];
[self.view addSubview:llVC.view];
[self repositionFields];
}
-(void)repositionFields {
// Reposition each view in the array
for (DetailViewController *llVC in self.playersArray) {
CGRect frame = llVC.view.frame;
frame.origin.x = 15;
frame.origin.y = self.yOffset;
llVC.view.frame = frame;
self.yOffset += frame.size.height;
}
// Add some animations to make it look nice
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.addPlayerButton.frame;
frame.origin.y = self.yOffset;
self.addPlayerButton.frame = frame;
} completion:^(BOOL finished) {
DetailViewController *llVC = [self.playersArray lastObject];
llVC.view.alpha = 1.0;
}];
}
从错误消息判断,您似乎将
yOffset
声明为UIView*
而不是CGFloat
,例如
@property (assign, nonatomic) UIView *yOffset;
然而它应该是
@property (assign, nonatomic) CGFloat yOffset;
如何声明
yOffset
?@属性(赋值,非原子)CGFloat*yOffset;这应该是CGFloat yOffset
,而不是CGFloat*yOffset
-您不希望它是指针。请发布实际代码和错误消息。你发布的那篇文章清楚地表明,你将其声明为@property(assign,非原子)UIView*yOffset代码>。这是我收到的错误消息。
-(void)addPlayerTapped:(id)sender {
NSLog(@"Adding Player");
self.yOffset = 60.0;
UIViewController *llVC = [[DetailViewController alloc] init];
llVC.view.alpha = 0.0;
[self.playersArray addObject:llVC];
[self.view addSubview:llVC.view];
[self repositionFields];
}
-(void)repositionFields {
// Reposition each view in the array
for (DetailViewController *llVC in self.playersArray) {
CGRect frame = llVC.view.frame;
frame.origin.x = 15;
frame.origin.y = self.yOffset;
llVC.view.frame = frame;
self.yOffset += frame.size.height;
}
// Add some animations to make it look nice
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.addPlayerButton.frame;
frame.origin.y = self.yOffset;
self.addPlayerButton.frame = frame;
} completion:^(BOOL finished) {
DetailViewController *llVC = [self.playersArray lastObject];
llVC.view.alpha = 1.0;
}];
}
@property (assign, nonatomic) UIView *yOffset;
@property (assign, nonatomic) CGFloat yOffset;