Question

//
//  ParkMeterViewController.h

@interface ParkMeterViewController : UIViewController <UIAlertViewDelegate>

{
    BOOL meterPickerIsDisplayed;
    BOOL reminderPickerIsDisplayed;
}

and then in the .m file

//
//  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];

}

Essentially I'm trying to get the isDisplayed variable in the method declaration to be the BOOL variable name that needs to be changed and then status as the new status for that BOOL.

Was it helpful?

Solution

What you are trying to achieve can be simply done by changing the method invocation - For example:

if (reminderPickerIsDisplayed == NO) {

    [self extendRetractPicker:reminderTimePicker andLabel:closeReminderLabel withPickerY:435 andLabelY:314];
    reminderPickerIsDisplayed=YES;

}

Or you could change the extendRetractPicker method to

- (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;
}

and then your invocation would simply be

reminderPickerIsDisplayed = [self extendRetractPicker:reminderTimePicker andLabel:closeReminderLabel withPickerY:435 andLabelY:314 isDisplayed:reminderPickerIsDisplayed];

OTHER TIPS

This just demonstrates how important it is to start all your instance variable with an underscore character, as everybody with a bit of Objective-C experience would tell you. You obviously were quite convinced that you assigned the BOOL parameter "status" to the BOOL instance variable "meterPickerIsDisplayed" or "reminderPickerIsDisplayed" (I don't know which one), so convinced actually that you attributed the compiler error message to some weirdness going on that you couldn't understand, while in reality you tried to assign the BOOL parameter "status" to the id parameter "isDisplayed". Which even if it had been legal wouldn't have made any sense.

It also shows how important it is to use sensible variable names. Why "withDisplayVar:(id)isDisplayed"? isDisplayed is how you would name a BOOL variable. It should have been called "idToDisplay" or something similar. Then if you had tried to assign

idToDisplay = status;

you'd have figured out that this looks wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top