Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将多个标记传递给addTarget:action:forControlEvents?_Ios_Tags_Ibaction - Fatal编程技术网

Ios 如何将多个标记传递给addTarget:action:forControlEvents?

Ios 如何将多个标记传递给addTarget:action:forControlEvents?,ios,tags,ibaction,Ios,Tags,Ibaction,我知道我写的代码是错误的。但我想要这样的东西。怎么做 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; int totalcout = 0; int passValue ; for(int j=0; j<5; j++{ for(int i=0; i<5; i++) { totalcout++; if(totalcount >1){

我知道我写的代码是错误的。但我想要这样的东西。怎么做

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
int totalcout = 0;
int passValue ;
for(int j=0; j<5; j++{
    for(int i=0; i<5; i++)
    {
        totalcout++;
        if(totalcount >1){
          break;
        }else{
        passValue = i;
        }
    }
    button.tag = j;
    [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
}


- (IBAction) button:(UIButton *)sender {
    NSLog(@"tag numbers are  %d", sender.tag);

    detailViewController.mutableArray1 = [oneMutableArray objectAtIndex:sender.tag];
    detailViewController.mutableArray2 = [twoMutableArray objectAtIndex:passValue];
}
UIButton*button=[UIButton button类型:UIButtonTypeCustom];
int totalcout=0;
整数通值;

对于(int j=0;j我明白了你的问题..你不能直接给任何UIView或任何子类分配两个标记。但是你可以间接地实现 希望这段代码能帮助你实现在最后得到两个标签的愿望

    #define First_Tag  100
    #define Second_Tag 200
  -(void)createButton
     {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = ((First_Tag*10000)+30000)+(Second_Tag*10);
   [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
      }

 - (void) button:(UIButton *)sender 
 {
   int intTag2 = ((sender.tag-30000)%10000)/10;
   int intTag1 = ((sender.tag-(intTag2*10))-30000)/10000;
   NSLog(@"tag numbers are  %d and %d", intTag1, intTag2);
  }

我使用了几个大数字来编码标记。希望分配两个标记能解决您的问题。

我明白您的问题。.您不能直接将两个标记分配给任何UIView或任何子类。但您可以间接实现 希望这段代码能帮助你实现在最后得到两个标签的愿望

    #define First_Tag  100
    #define Second_Tag 200
  -(void)createButton
     {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = ((First_Tag*10000)+30000)+(Second_Tag*10);
   [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
      }

 - (void) button:(UIButton *)sender 
 {
   int intTag2 = ((sender.tag-30000)%10000)/10;
   int intTag1 = ((sender.tag-(intTag2*10))-30000)/10000;
   NSLog(@"tag numbers are  %d and %d", intTag1, intTag2);
  }

我使用了几个大数字来编码标记。希望分配两个标记能解决您的问题。

我明白您的问题。.您不能直接将两个标记分配给任何UIView或任何子类。但您可以间接实现 希望这段代码能帮助你实现在最后得到两个标签的愿望

    #define First_Tag  100
    #define Second_Tag 200
  -(void)createButton
     {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = ((First_Tag*10000)+30000)+(Second_Tag*10);
   [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
      }

 - (void) button:(UIButton *)sender 
 {
   int intTag2 = ((sender.tag-30000)%10000)/10;
   int intTag1 = ((sender.tag-(intTag2*10))-30000)/10000;
   NSLog(@"tag numbers are  %d and %d", intTag1, intTag2);
  }

我使用了几个大数字来编码标记。希望分配两个标记能解决您的问题。

我明白您的问题。.您不能直接将两个标记分配给任何UIView或任何子类。但您可以间接实现 希望这段代码能帮助你实现在最后得到两个标签的愿望

    #define First_Tag  100
    #define Second_Tag 200
  -(void)createButton
     {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = ((First_Tag*10000)+30000)+(Second_Tag*10);
   [button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
      }

 - (void) button:(UIButton *)sender 
 {
   int intTag2 = ((sender.tag-30000)%10000)/10;
   int intTag1 = ((sender.tag-(intTag2*10))-30000)/10000;
   NSLog(@"tag numbers are  %d and %d", intTag1, intTag2);
  }


我用了几个大数字来编码标签。希望分配两个标签能解决您的问题。

什么是
tag1
tag2
?您想用这两个标签实现什么?如果您想为不同的UIButton调用相同的iAction方法,那么您需要在iAction方法中比较标签。这是您想要的吗你想要什么?你能更清楚地分享吗?你只是想给同一个按钮分配两个标签吗?为什么要这样做?什么是
tag1
tag2
?你想用这两个标签实现什么?如果你想为不同的UIButton调用相同的iAction方法,那么你需要在iAct中比较标签ion方法。这就是你想要的吗?你想要什么?你能更清楚地分享吗?你只是想给同一个按钮分配两个标签吗?你为什么要这样做?什么是
tag1
tag2
?你想用这两个标签实现什么?如果你想为不同的UIButton调用相同的iAction方法,那么您需要在iAction方法中比较标记。这就是您想要的吗?您想要什么?您可以更清楚地共享吗?您是否只是尝试将两个标记分配给同一个按钮?您为什么要这样做?什么是
tag1
tag2
?您试图用这两个标记实现什么?如果您想要调用相同的IBActi在不同UIButton的方法上,然后你需要比较IBAction方法中的标记。这就是你要找的吗?你想要什么?你能更清楚地分享一下吗?你只是想给同一个按钮分配两个标记吗?你为什么要这样做?我觉得太傻了…添加两个所需的标记,然后从中减去一个真的很简单我是另一个再次得到两个标记的人…就像不使用第三个变量交换两个整数的解决方案我觉得很愚蠢…它真的很简单,添加两个所需的标记,然后从另一个中减去一个来再次得到两个标记…就像不使用第三个变量交换两个整数的解决方案我觉得很愚蠢…这很简单真的很简单,加上两个想要的标签,然后从另一个标签中减去一个,再得到两个标签…就像不使用第三个变量交换两个整数的解决方案我觉得很愚蠢…这真的很简单,加上两个想要的标签,然后从另一个标签中减去一个,再得到两个标签…就像swa的解决方案一样在不使用第三个变量的情况下映射两个整数