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 t开发者_C百科he 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 ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ] [ _ ]
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:
@property (nonatomic, retain) IBOutletCollection(UILabel) NSArray *labels;
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:
for (UILabel *label in self.labels)
{
if (label.tag == whateverIntYouCareAbout)
{
//Do stuff
break;
}
}
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;
using cell1
So it is the label1
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 of label3
,if its 7 then change the text of label7
. 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.
精彩评论