简体   繁体   English

如何将按钮标签设置为数组入口点的数组

[英]How to set a button tag to an array of arrays entry point

I need some help. 我需要协助。 I'm currently learning objective c and I'm trying to do the following: 我目前正在学习目标c,并且正在尝试执行以下操作:

Add to story board a button(action) textfield & label(checked) type in a number in the text field press the button=>create oa new row a new button with as many text field as requested previously.(checked) Store each new button+ it's text fields into an array, then store that array in a new array, rows and columns[0][0] etc style(checked) Add for each new button I create a tag and use array count method for it to identify my button(checked). 将添加到故事板上的按钮(动作)文本字段和标签(选中)在文本字段中键入数字,然后按一下按钮=>在新行中创建一个新按钮,该按钮的文本字段的数量与以前的要求相同。(选中)存储每个新按钮button +是将文本字段放入一个数组,然后将该数组存储在新数组,行和列中[0] [0]等样式(已选中)为每个新按钮添加一个标签,并使用数组计数方法来识别我的标签按钮(选中)。 I do this because each array looks like this [0]button[1]textfield[2]textfield and so on with only textfields following. 我这样做是因为每个数组看起来像[0] button [1] textfield [2] textfield,依此类推,后面只有文本字段。

Now here is my code to create my button: 现在,这里是我创建按钮的代码:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(_x, _y, 100.0, 30.0);
[button setTitle:@"Calculate" forState:UIControlStateNormal];
button.tag = [_arayOfArays count];
[button addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

And this is my method that calls it: 这是我调用它的方法:

-(void)myAction:(UIControl*)sender{


if ([[_arayOfArays objectAtIndex:sender]count] == 4) {

 //here i call another method that calculates the area of a triangle if the button I would press would be in a same array with another 3 text fields 
}

Now my problem is that my sender address memory always points to [0][0] or [1][0] and so on depending on what i pressed, and I want it to point to [0] or [1] and so on so I can use the count method. 现在我的问题是我的发件人地址存储器始终指向[0] [0]或[1] [0],依此类推,具体取决于我按下的内容,我希望它指向[0]或[1],依此类推这样我就可以使用count方法了。

Can anyone please give me a hint on how I achieve this? 谁能给我一个有关我如何实现的提示? Thanks and sorry for the long post. 谢谢,对不起,很长的帖子。

您可能打算像这样通过button标记指定的索引处访问元素:

[_arayOfArays objectAtIndex:sender.tag]

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

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