//
// ParkMeterViewController.h
@interface ParkMeterViewController : UIViewController <UIAlertViewDelegate>
{
BOOL meterPickerIsDisplayed;
BOOL reminderPickerIsDisplayed;
}
然后在.m文件中
//
// ParkMeterViewController.m
- (void)extendRetractPicker:(UIDatePicker *)picker
andLabel:(UILabel*)label
withPickerY:(int)pickerY
andLabelY:(int)labelY
withDisplayVar:(id)isDisplayed
andDisplaySet:(BOOL)status {
[UIView animateWithDuration:.5
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
picker.center = CGPointMake(picker.frame.origin.x + (picker.frame.size.width/2), pickerY);
label.center = CGPointMake(label.frame.origin.x + (label.frame.size.width/2), labelY);
}
completion:nil];
isDisplayed = status;
}
//call for the method
if (reminderPickerIsDisplayed == NO) {
[self extendRetractPicker:reminderTimePicker andLabel:closeReminderLabel withPickerY:435 andLabelY:314 withDisplayVar:reminderPickerIsDisplayed andDisplaySet:YES];
}
基本上我试图让方法声明中的isDisplayed变量成为需要更改的BOOL变量名,然后将状态作为该BOOL的新状态。
答案 0 :(得分:0)
您尝试实现的目标可以通过更改方法调用来完成 - 例如:
if (reminderPickerIsDisplayed == NO) {
[self extendRetractPicker:reminderTimePicker andLabel:closeReminderLabel withPickerY:435 andLabelY:314];
reminderPickerIsDisplayed=YES;
}
或者您可以将extendRetractPicker
方法更改为
- (BOOL)extendRetractPicker:(UIDatePicker *)picker
andLabel:(UILabel*)label
withPickerY:(int)pickerY
andLabelY:(int)labelY
isDisplayed:(BOOL)isDisplayed {
[UIView animateWithDuration:.5
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
picker.center = CGPointMake(picker.frame.origin.x + (picker.frame.size.width/2), pickerY);
label.center = CGPointMake(label.frame.origin.x + (label.frame.size.width/2), labelY);
}
completion:nil];
return !isDisplayed;
}
然后你的调用只是
reminderPickerIsDisplayed = [self extendRetractPicker:reminderTimePicker andLabel:closeReminderLabel withPickerY:435 andLabelY:314 isDisplayed:reminderPickerIsDisplayed];
答案 1 :(得分:0)
这只是展示了使用下划线字符启动所有实例变量的重要性,因为每个有一点Objective-C经验的人都会告诉你。您显然确信您已将BOOL参数“status”分配给BOOL实例变量“meterPickerIsDisplayed”或“reminderPickerIsDisplayed”(我不知道哪一个),因此确信您将编译器错误消息归因于一些奇怪的事情。你无法理解,而实际上你试图将BOOL参数“status”分配给id参数“isDisplayed”。即使它是合法的,也没有任何意义。
它还显示了使用合理变量名称的重要性。为什么“withDisplayVar:(id)isDisplayed”? isDisplayed是如何命名BOOL变量的。它应该被称为“idToDisplay”或类似的东西。然后,如果你试图分配
idToDisplay = status;
你已经发现这看起来不对劲了。