<legend id='KjZ5f'><style id='KjZ5f'><dir id='KjZ5f'><q id='KjZ5f'></q></dir></style></legend>

<small id='KjZ5f'></small><noframes id='KjZ5f'>

<i id='KjZ5f'><tr id='KjZ5f'><dt id='KjZ5f'><q id='KjZ5f'><span id='KjZ5f'><b id='KjZ5f'><form id='KjZ5f'><ins id='KjZ5f'></ins><ul id='KjZ5f'></ul><sub id='KjZ5f'></sub></form><legend id='KjZ5f'></legend><bdo id='KjZ5f'><pre id='KjZ5f'><center id='KjZ5f'></center></pre></bdo></b><th id='KjZ5f'></th></span></q></dt></tr></i><div id='KjZ5f'><tfoot id='KjZ5f'></tfoot><dl id='KjZ5f'><fieldset id='KjZ5f'></fieldset></dl></div>
  • <tfoot id='KjZ5f'></tfoot>

        • <bdo id='KjZ5f'></bdo><ul id='KjZ5f'></ul>

        UIControl - 更改分配的选择器:addTarget &amp;移除目标

        时间:2023-07-08

          <i id='1LxD0'><tr id='1LxD0'><dt id='1LxD0'><q id='1LxD0'><span id='1LxD0'><b id='1LxD0'><form id='1LxD0'><ins id='1LxD0'></ins><ul id='1LxD0'></ul><sub id='1LxD0'></sub></form><legend id='1LxD0'></legend><bdo id='1LxD0'><pre id='1LxD0'><center id='1LxD0'></center></pre></bdo></b><th id='1LxD0'></th></span></q></dt></tr></i><div id='1LxD0'><tfoot id='1LxD0'></tfoot><dl id='1LxD0'><fieldset id='1LxD0'></fieldset></dl></div>
            <bdo id='1LxD0'></bdo><ul id='1LxD0'></ul>

            <small id='1LxD0'></small><noframes id='1LxD0'>

                  <tbody id='1LxD0'></tbody>
                <legend id='1LxD0'><style id='1LxD0'><dir id='1LxD0'><q id='1LxD0'></q></dir></style></legend>

                1. <tfoot id='1LxD0'></tfoot>
                  本文介绍了UIControl - 更改分配的选择器:addTarget &amp;移除目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在界面中使用了 10 个按钮,并且需要不时更改按钮的选择器.

                  I'm using 10 buttons in my interface and need, from time to time, to change the button's selector.

                  我需要使用吗:

                  -(void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents 
                  

                  在我更改选择器之前或者我可以使用:

                  before I change the selector or can I just use:

                  -(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents 
                  

                  我担心如果我使用 addTarget: 方法更改选择器而不使用 removeTarget: 方法,我基本上会堆叠"选择器,以便我的 UIButton 在按下时触发.

                  I'm concerned that if I change the selector using the addTarget: method sans the removeTarget: method that I'll essentially "stack up" selectors for my UIButton to fire when it is pressed.

                  推荐答案

                  是的,在将新目标分配给按钮之前,您应该始终删除之前添加的目标.像这样---

                  Yes you should always remove the previously add target before assigning the new target to the button. Like this---

                  UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                      [btn setFrame:CGRectMake(50, 50, 200, 50)];
                  
                      [btn setTag:101];
                      [btn addTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];
                      [self.view addSubview:btn];
                  
                  
                      btn = (UIButton *)[self.view viewWithTag:101];
                      [btn removeTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];
                      [btn addTarget:self action:@selector(method2) forControlEvents:UIControlEventTouchUpInside];
                  

                  现在如果你这样做

                  btn = (UIButton *)[self.view viewWithTag:101];
                          [btn addTarget:self action:@selector(method2) forControlEvents:UIControlEventTouchUpInside];
                  

                  那么方法method1和method2都会被调用.

                  then both the methods method1 and method2 will be called.

                  希望这会有所帮助.

                  这篇关于UIControl - 更改分配的选择器:addTarget &amp;移除目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:触摸时淡出 UIButton 下一篇:自定义 UITableViewCell 中使用的 UIButton 没有响应

                  相关文章

                    <bdo id='I7y4P'></bdo><ul id='I7y4P'></ul>
                2. <tfoot id='I7y4P'></tfoot>

                    <small id='I7y4P'></small><noframes id='I7y4P'>

                  1. <i id='I7y4P'><tr id='I7y4P'><dt id='I7y4P'><q id='I7y4P'><span id='I7y4P'><b id='I7y4P'><form id='I7y4P'><ins id='I7y4P'></ins><ul id='I7y4P'></ul><sub id='I7y4P'></sub></form><legend id='I7y4P'></legend><bdo id='I7y4P'><pre id='I7y4P'><center id='I7y4P'></center></pre></bdo></b><th id='I7y4P'></th></span></q></dt></tr></i><div id='I7y4P'><tfoot id='I7y4P'></tfoot><dl id='I7y4P'><fieldset id='I7y4P'></fieldset></dl></div>
                    <legend id='I7y4P'><style id='I7y4P'><dir id='I7y4P'><q id='I7y4P'></q></dir></style></legend>