我是记分牌应用程序,在按钮点击时我不需要添加UItextfield和标签。我不断在这些方法中遇到错误。有什么建议吗?
错误讯息: “从不兼容的类型'double'分配'UIView *'”
self.yOffset = 60.0;
错误讯息: “从不兼容的类型'UIView *'中分配'CGFloat'(又名'浮动')”
frame.origin.y = self.yOffset;
错误讯息: “二进制表达式的操作数无效('UIView *'和'CGFloat'(又名'浮动'))”
self.yOffset += frame.size.height;
以下是代码:
-(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;
}];
}
答案 0 :(得分:2)
从错误消息判断,您似乎将yOffset
声明为UIView *
而不是CGFloat
,例如
@property (assign, nonatomic) UIView *yOffset;
然而它应该是
@property (assign, nonatomic) CGFloat yOffset;