如何让下一个 IBAction 影响下一个空 IBoutet UILabel?
我有 12 个带有 0-11 标签的按钮。当用户单击按钮时,标签将插入 12 个标签出口中的第一个。我希望下一个单击的按钮自动将其标签插入到下一个可用的插座中。到目前为止,标签只是将其自身添加到第一个出口。我尝试了多种修复方法,但没有效果。
这是我迄今为止的实现:
-(IBAction)enterNumber:(id)sender {
cell1 = cell1+(int)[sender tag];
label1.text = [NSString stringWithFormat:@"%i",cell1];
}
我的问题是让下一个 IBAction 仅在 cell2 中显示(我认为此帮助将引导我使用 cell3-cell12 的修复程序)。我的书籍建议都没有为我有限的知识提供合适的过程。
在 Danillo 之后编辑,
我没有考虑过 IBOutletCollection,我肯定会尝试使用它!对于其他想要更清楚地解决我的问题的人,我将尝试代表用户将要使用的屏幕的一部分。相互影响顶部的数字是固定按钮。底部的方块是按顺序记录到该系列的单击的顶部按钮的位置,我希望下次单击任何顶部按钮时都记录到第二个按钮。底部正方形,但发生的情况是该整数被添加到第一个框中的整数
(1) - (2) - (3) - (4) - (5) - (6)
[ 4 ] [ _ 。 ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ]
I have 12 Buttons with 0-11 tagged. When the user clicks the button the tag is inserted into the first of 12 label outlets. I want the next clicked button to automatically insert its tag into the next available outlet. As of now the tag simply adds itself to the first outlet. I have tried a variety of fixes, but to no avail.
This is my implementation thus far:
-(IBAction)enterNumber:(id)sender {
cell1 = cell1+(int)[sender tag];
label1.text = [NSString stringWithFormat:@"%i",cell1];
}
My problem is getting the next IBAction to display only in cell2 (I assume this help will lead me to use the fix for cell3-cell12. None of my books' suggestions provide suitable processes to my limited knowledge.
Edited after Danillo
I hadn't considered the IBOutletCollection, I hadn't heard of it! I will certainly try to use it. For the others who wanted a clearer question to my problem I will attempt represent part of the screen that the user will interact with. The top numbers are fixed buttons. The bottom squares are where the clicked top buttons' tags are logged sequentially to the series. I just clicked (4). I would like the next click of any top button to be logged into the second bottom square, but what is happening is that the integer is being added to the integer in the first box.
(1) - (2) - (3) - (4) - (5) - (6)
[ 4 ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来好像您想要做的就是按顺序向一系列标签提供内容。如果这是正确的,这就是我将采取的方法:
iOS 4 及更高版本支持插座集合,这些集合作为数组公开供您使用,其中填充了您分配的任何对象。
因此,就像标记按钮一样,标记标签。然后,在 .h 文件中,声明一个插座集合,如下所示:
控制拖动每个标签以将其连接到该插座集合。
然后,当需要将内容分配给标签时,迭代集合:
It sounds as though what you are trying to do is provide content sequentially to a series of labels. If that is correct, this is the approach I would take:
iOS 4 and later supports outlet collections, which are exposed for your use as arrays filled with whatever objects you've assigned.
So, just as you've tagged your buttons, tag your labels. Then, in your .h file, declare an Outlet Collection like so:
Control drag each label to wire it to that outlet collection.
Then, when it's time to assign content to a label, iterate through the collection:
从你所说的“但发生的事情是,该整数被添加到第一个框中的整数”。我相信您的问题只能在第一个标签中显示数字。这是因为在您的方法中,您使用
cell1
将标签的文本设置为label1.text = someValue;
所以它是label1
始终更新。您应该获得按钮相应标签的标签。例如,如果您的标签为 3,则应更改label3
的文本,如果为 7,则应更改label7
的文本。还要确保您的电池是否需要相应更改。这是我从你提到的内容中了解到的。如果我错了请纠正我。From what you said "but what is happening is that the integer is being added to the integer in the first box." I believe your problem you are able to display the number in the first label only. This is because in your method you are setting the text for the label as
label1.text = someValue;
usingcell1
So it is thelabel1
which is always updated. You should get the label for the corresponding tag of the button. For example if your tag is 3 then you should change the text oflabel3
,if its 7 then change the text oflabel7
. Also make sure if your cell needs to be changed accordingly. This is what I understood from what you mentioned. Correct me if I am wrong.