Question

I have 2 different buttons that trigger a different set of annotations in a single mapview. I have action methods that fade out the buttons at which point an annotation should appear, but I cannot figure out how to say in the annotation method "if this action is activated, then load annotations from this class." So here is my current code

- (void)queryForAllPostsNearLocation:(CLLocation *)currentLocation withNearbyDistance:(CLLocationAccuracy)nearbyDistance {
if (????? IBAction 1 is activated ?????) {
    NSString *button1 = @"Today";
}
if (????? IBAction 2 is activated ?????) {
    NSString *button1 = @"Tomorrow";
}
PFQuery *query = [PFQuery queryWithClassName:button1];

I hope that I am conveying my problem appropriately and someone can help me out.

Was it helpful?

Solution

If you're asking what I think you're asking, and by "activated" you mean "has been touched"/"has been selected", you're doing things backwards. Instead of checking whether the button has been selected within your queryForAllPostsNearLocation method, have your button trigger the necessary query. In the following example, I've made button1 and button2 correspond to the UIButtons and I've replaced NSString *button1 with NSString *buttonText just to make things a bit clearer.

- (IBAction)buttonSelected:(id)sender {
    NSString *buttonText;
    if (sender == button1)
        buttonText = @"Today";
    else
        buttonText = @"Tomorrow";

    PFQuery *query = [PFQuery queryWithClassName:buttonText];
}

Edit: In order to complete your desired query in this case, you can either (1) store currentLocation and nearbyDistance as class variables then access them within buttonSelected in order to complete the query there or (2) you can fetch the currentLocation and nearbyDistance values within buttonSelected then call a method like

// Modified to now include the button's text as an argument
-(void)queryForAllPostsNearLocation:(CLLocation *)currentLocation withNearbyDistance:(CLLocationAccuracy)nearbyDistance withButtonText(NSString*)buttonText

from within buttonSelected, then perform the query from there.

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