簡體   English   中英

如何將按鈕標簽設置為數組入口點的數組

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

我需要協助。 我目前正在學習目標c,並且正在嘗試執行以下操作:

將添加到故事板上的按鈕(動作)文本字段和標簽(選中)在文本字段中鍵入數字,然后按一下按鈕=>在新行中創建一個新按鈕,該按鈕的文本字段的數量與以前的要求相同。(選中)存儲每個新按鈕button +是將文本字段放入一個數組,然后將該數組存儲在新數組,行和列中[0] [0]等樣式(已選中)為每個新按鈕添加一個標簽,並使用數組計數方法來識別我的標簽按鈕(選中)。 我這樣做是因為每個數組看起來像[0] button [1] textfield [2] textfield,依此類推,后面只有文本字段。

現在,這里是我創建按鈕的代碼:

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

這是我調用它的方法:

-(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 
}

現在我的問題是我的發件人地址存儲器始終指向[0] [0]或[1] [0],依此類推,具體取決於我按下的內容,我希望它指向[0]或[1],依此類推這樣我就可以使用count方法了。

誰能給我一個有關我如何實現的提示? 謝謝,對不起,很長的帖子。

您可能打算像這樣通過button標記指定的索引處訪問元素:

[_arayOfArays objectAtIndex:sender.tag]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM