繁体   English   中英

IBAction连接到IF语句

[英]IBAction connected to IF statement

我有2个不同的按钮,可在一个mapview中触发一组不同的注释。 我有一些操作方法可以淡出应该在其中出现注释的按钮,但是我无法弄清楚在注释方法中如何说“如果激活此操作,然后从此类加载注释”。 所以这是我当前的代码

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

我希望我能适当地传达我的问题,并且有人可以帮助我。

如果您要问的是我想问的问题,并且“激活”是指“已被感动” /“已被选择”,则表示您在做反向操作。 让您的按钮触发必要的查询,而不是检查在queryForAllPostsNearLocation方法中是否已选择按钮。 在下面的示例中,我将button1button2为与UIButtons对应,并且将NSString *button1替换为NSString *buttonText只是为了使内容更清晰。

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

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

编辑:在这种情况下,为了完成所需的查询,您可以(1)将currentLocation和附近的距离存储为类变量,然后在buttonSelected中访问它们以在buttonSelected完成查询,或者(2)您可以获取currentLocationnearbyDistance值在buttonSelected内,然后调用类似

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

buttonSelected内部,然后从那里执行查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM