首页 \ 问答 \ 在alertView if语句中调用IBaction(Calling an IBaction in a alertView if statement)

在alertView if语句中调用IBaction(Calling an IBaction in a alertView if statement)

我和我的朋友正在开发一款应用程序,我们都是新手,但通过书籍和护目镜已经有很长的路要走。

我们现在被困在这件事上。 我们有一堆texfields,通过这个动作,我们有清楚的按钮链接到它,但是,如果您在其中一个警报视图按钮上单击“是”,我们希望该动作被调用。

- (IBAction)clearText:(id)sender {

Spelare1Slag1.text = @"";
Spelare1Slag2.text = @"";

}

我们也有这个警报视图:

        alertDialog = [[UIAlertView alloc]
    initWithTitle: @"Warning"
    message: @"Do you want to delete?"
    delegate: self
    cancelButtonTitle: @"No"
    otherButtonTitles: @"Yes", nil];

- (void)alertView: (UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
    if ([buttonTitle isEqualToString:@"No"]) {
    }

    else if ([buttonTitle isEqualToString:@"Yes"]){
        Spelare1Slag1.text = @"";
    }

}

所以这就是我们认为我们应该这样做的方式,但我们不知道应该在else if语句中放置什么。 我们希望在警报视图中按下“是”按钮时清除文本框,而不是按“否”

提前致谢!


Me and my buddy are working on an app, we're total newbies but have come a long way with books and goggling.

We're stuck now on this thing. We have a bunch of texfields that we have clear button linked to it with this action, but then we want that action to be called if you click "Yes" on one of the alert view buttons.

- (IBAction)clearText:(id)sender {

Spelare1Slag1.text = @"";
Spelare1Slag2.text = @"";

}

We also have this alert view:

        alertDialog = [[UIAlertView alloc]
    initWithTitle: @"Warning"
    message: @"Do you want to delete?"
    delegate: self
    cancelButtonTitle: @"No"
    otherButtonTitles: @"Yes", nil];

- (void)alertView: (UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
    if ([buttonTitle isEqualToString:@"No"]) {
    }

    else if ([buttonTitle isEqualToString:@"Yes"]){
        Spelare1Slag1.text = @"";
    }

}

So this is how we think we should do it, but we don't know what to put in the else if statement. We want the textfields to clear when you press the "yes" button in the alert view, and not when you press "no"

Thanks in advance!


原文:https://stackoverflow.com/questions/14864841
更新时间:2023-08-03 06:08

最满意答案

您可以在render()内切换标记,或只使用<component>

根据动态组件官方规范

您可以使用相同的挂载点,并使用保留的<component>元素在多个组件之间动态切换,并动态绑定到它的is属性。

以下是您案例的示例:

ButtonControl.vue

<template>
  <component :is="type" :to="to">
    {{ value }}
  </component>
</template>

<script>
export default {
  computed: {
    type () {
      if (this.to) {
        return 'router-link'
      }

      return 'button'
    }
  },

  props: {
    to: {
      required: false
    },
    value: {
      type: String
    }
  }
}
</script>

现在您可以轻松地将其用作button

<button-control value="Something"></button-control>

router-link

<button-control to="/" value="Something"></button-control>

当需要创建可能具有链接或不具有链接的元素(例如按钮或卡片)时,这是一个很好的行为。


You can toggle the tag inside render() or just use <component>.

According to the official specification for Dynamic Components:

You can use the same mount point and dynamically switch between multiple components using the reserved <component> element and dynamically bind to it's is attribute.

Here's an example for your case:

ButtonControl.vue

<template>
  <component :is="type" :to="to">
    {{ value }}
  </component>
</template>

<script>
export default {
  computed: {
    type () {
      if (this.to) {
        return 'router-link'
      }

      return 'button'
    }
  },

  props: {
    to: {
      required: false
    },
    value: {
      type: String
    }
  }
}
</script>

Now you can easily use it for a button:

<button-control value="Something"></button-control>

Or a router-link:

<button-control to="/" value="Something"></button-control>

This is an excellent behavior to keep in mind when it's necessary to create elements that may have links or not, such as buttons or cards.

相关问答

更多
  • 您可以在render()内切换标记,或只使用 。 根据动态组件的官方规范 : 您可以使用相同的挂载点,并使用保留的元素在多个组件之间动态切换,并动态绑定到它的is属性。 以下是您案例的示例: ButtonControl.vue