gpt4 book ai didi

ios - 如何将多个标签传递给 addTarget :action:forControlEvents?

转载 作者:行者123 更新时间:2023-11-28 20:05:41 24 4
gpt4 key购买 nike

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

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

我希望问题很清楚。提前谢谢你

最佳答案

我明白你的问题了。你不能直接将两个标签直接分配给任何 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);
}

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

关于ios - 如何将多个标签传递给 addTarget :action:forControlEvents?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22172352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com