I have created 3 buttons at my top.take the offset of them and giving them same IBAction.
I want to change images at below according to the which button is pressed.
Further i have to pass these images to the another ViewControler, Here
i have got 3 arrays named bundle1 , bundle2 , bundle3 . in each array i have set of 5 images, in my Viewdidload as below,
bundle1 = #[#"1.png",#"2.png", #"3.png", #"4.png" ,#"5.png"];
bundle2 = #[#"6.png", #"7.png", #"8.gif",#"9.jpeg", #"10.jpeg" ];
bundle3 = #[#"11.jpg", #"12.jpg" ,#"13.jpeg", #"14.jpeg", #"15.jpeg"];
now i had take mutabledictionary, which had upper 3 arrays and i had give them a specific key
as below.
mutdict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: bundle1 , #"key1" , bundle2 , #"key2" , bundle3 , #"key3" ,nil];
Now below is the code for IBAction of Upper 3 buttons, (Which is the same for all 3 buttons).
-(IBAction)morebtn:(id)sender
{
for (UIView *subview in [scroll subviews])
{
[subview removeFromSuperview];
}
arraydata = [[NSMutableArray alloc] init];
if ([sender tag] == 1) {
NSLog(#"hey btn1 clicked");
for (UIImage *b in arraydata)
{
[arraydata removeAllObjects];
}
arraydata = [mutdict valueForKey:#"key1"];
}
if ([sender tag] == 2) {
NSLog(#"hey btn2 clicked");
for (UIImage*b in arraydata)
{
[arraydata removeAllObjects];
}
arraydata = [mutdict valueForKey:#"key2"];
}
if ([sender tag] == 3) {
NSLog(#"hey btn3 clicked");
for (UIImage*b in arraydata)
{
[arraydata removeAllObjects];
}
arraydata = [mutdict valueForKey:#"key3"];
}
int x=10,y=300;
for (int k=0; k<arraydata.count; k++) {
NSLog(#"main called");
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:[arraydata objectAtIndex:k]] forState:UIControlStateNormal];
btn.tag=k;
btn.frame=CGRectMake(x, y, 100, 100);
[btn addTarget:self action:#selector(btn4images1:) forControlEvents:UIControlEventTouchUpInside];
x+=100;
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 300, self.view.frame.size.width, 200)];
scroll.contentSize = CGSizeMake(self.view.frame.size.width , 200);
[scroll addSubview:btn];
[self.view addSubview:scroll];
}
}
in upper code i trace which button is pressed and according to it i wil give inages in my NSArray named arraydata.
when i first time click on the all 3 upper buttons they show me image related to their array, but when i second time click on button1 (placed on the top), The images related to button3 are also shown in the Buttonbackground (palced at below part).
so on clicking button1 in below part button background images are overlaped. Seems like my NSMutableDictionary stores the data of last array. don't know what exactly happen.
Related
In my app I'm picking five images at a time and displaying in a small view and I have button if I click that button the 5 images in that view should go to next View Controller .but when I'm clicking that button only the image in 0th index is passing and remaining images are not passing.Hope someone helps me
And here is my code.This code is for passing from first view to second view and chosenImages is an array where all the picked images are saving
SecondViewController *secview=[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
if (secview.imgView.tag==0) {
secview.img=[self.chosenImages objectAtIndex:0];
}
else if (secview.imgView1.tag==1)
{
secview.img=[self.chosenImages objectAtIndex:1];
}
else if (secview.imgView1.tag==2)
{
secview.img=[self.chosenImages objectAtIndex:2];
}
else if (secview.imgView1.tag==3)
{
secview.img=[self.chosenImages objectAtIndex:3];
}
else if (secview.imgView1.tag==4)
{
secview.img=[self.chosenImages objectAtIndex:4];
}
NSLog(#"%#",secview.img);
[self presentViewController:secview animated:YES completion:nil];
and in second view my code is:
if (imgView.tag==0)
{
imgView.image=img;
}
else if (imgView1.tag==1)
{
imgView1.image=img;
}
else if (imgView2.tag==2)
{
imgView2.image=img;
}
else if (imgView3.tag==3)
{
imgView3.image=img;
}
else if (imgView4.tag==4)
{
imgView4.image=img;
}
Update:In didFinishPickingMedia I wrote this code
images = [NSMutableArray arrayWithCapacity:[info count]];
for (NSDictionary *dict in info) {
if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypePhoto){
if ([dict objectForKey:UIImagePickerControllerOriginalImage]){
image=[dict objectForKey:UIImagePickerControllerOriginalImage];
[images addObject:image];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
}
}
else {
NSLog(#"UIImagePickerControllerReferenceURL = %#", dict);
}
}
self.chosenImages = images;
[AllImages setHidden:NO];
previousButtonTag=1000;
scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 4, self.AllImages.frame.size.width, 104)];
int x =0.5;
for (int i=0; i<5; i++) {
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(x, 0, 100, 123);
button.layer.borderWidth=0.5;
button.titleLabel.font=[UIFont boldSystemFontOfSize:12];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
// button.layer.borderColor=[[UIColor lightGrayColor]CGColor];
button.tag = i;
[button setBackgroundImage:[self.chosenImages objectAtIndex:i] forState:UIControlStateNormal];
[button addTarget:self action:#selector(OverLayMethod:) forControlEvents:UIControlEventTouchUpInside];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[scrollView addSubview:button];
x += button.frame.size.width;
x=x+6.0;
}
scrollView.contentSize = CGSizeMake(x, scrollView.frame.size.height);
scrollView.backgroundColor = [UIColor clearColor];
[self.AllImages addSubview:scrollView];
}
I solved my issue by declaring another array in second view.In first view we are saving picked images in one array .so that first view array objects = second view array and I passed that array in second view
my code in second view :
for (int i=0; i<[arr count]; i++) {
self.img=[arr objectAtIndex:i];
if (i==0)
{
imgView.image=img;
}
else if (i==1)
{
imgView1.image=img;
}
else if (i==2)
{
imgView2.image=img;
}
else if (i==3)
{
imgView3.image=img;
}
else if (i==4)
{
imgView4.image=img;
}
}
}
by this i'm getting correct output
I dunno that I got your question but my understanding is that you wanna send 5 images to another view. If so, define a new NSArray property such as 'images' in your SecondViewController and add it to where you go from first view to second
SecondViewController *secondVC = [SecondViewController new];
[secondVC setImages: self.chosenImages];
The problem with your code is that you're using if/else if block statement and if one of the conditions in that if/else if evaluate to true only you get into one of the block. Also, -objectAtIndex: only returns one item.
[self.chosenImages objectAtIndex:0];
Also, I'm sure that secview.img means that you have a UIImage property inside your SecondViewController.
I have n number of buttons in the scrollView. If click on a button its text color is changing but if I click another button the text color of the previous button remain unchanged. I want to change the previous button text color as default color while clicking another button. The behavior will be just like a segmented control. Please help me regarding this, I've providing my code below:
-(void) loadScrollView:(CGRect)scrollViewFrame withButtonArray:(NSArray*)buttonArray withCase: (int)ButtonCase
{
scrollView=[[UIScrollView alloc]initWithFrame:scrollViewFrame];
[scrollView setScrollEnabled:YES];
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setContentSize:CGSizeMake(100 * 768, 40)];
for (int i = 0; i < [buttonArray count]; i++)
{
adButtonOutLet = [[UIButton alloc] initWithFrame:CGRectMake(140*i, 0, 135, 40)];
if (ButtonCase==0) {
[adButtonOutLet setBackgroundColor:UIColorFromRGB(0X272c2f)];
[adButtonOutLet setTitleColor:UIColorFromRGB(0x969696) forState:UIControlStateNormal];
}
else
{
if (i==0) {
adButtonOutLet.backgroundColor=UIColorFromRGB(0x000000) ;
[adButtonOutLet setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
}
}
adButtonOutLet.titleLabel.font=[UIFont fontWithName:#"MyriadPro" size:14.0];
[adButtonOutLet setTitle:[buttonArray objectAtIndex:i] forState:UIControlStateNormal];
adButtonOutLet.userInteractionEnabled= YES;
[adButtonOutLet setTag:i];
[adButtonOutLet addTarget:self action:#selector(adButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:adButtonOutLet];
[self.view addSubview:scrollView];
}
}
Here is my action method:
-(void)adButtonAction:(UIButton*)sender
{
for (int i = 0; i < [menuArray count]; i++)
{
int prevTag = 0;
if (sender.tag == i && Case==0)
{
[self reloadScrollViewwithButtonTag:i];
// [sender setSelected:YES];
sender.backgroundColor=UIColorFromRGB(0x000000) ;
[sender setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
prevTag=i;
}
if (Case==1) {
sender.backgroundColor=UIColorFromRGB(0x000000) ;
[sender setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
if (sender.tag==prevTag-1) {
[sender setBackgroundColor:UIColorFromRGB(0X272c2f)];
[sender setTitleColor:UIColorFromRGB(0x969696) forState:UIControlStateNormal];
}
}
}
}
Why don't you try changing all buttons style to no selected except the one that is on the sender parameter (selected button)?
-(void)adButtonAction:(UIButton*)sender{
for (int i = 0; i < [menuArray count]; i++)
{
if (sender == menuArray[i])
{
//Selected code style
}
else{
//No selected code style
}
}
}
Considering menuArray is an array with all buttons.
This way you check and modify all styles when a button is pressed.
Hope this could help you or at last give you a clue for resolve your problem.
I don' understand everything in your adButtonAction (what is menuArray?) method but I think what you need is simple, just adapt it to your method.
First create a NSMutableArray to keep reference on your button list:
for (int i = 0; i < [buttonArray count]; i++)
{
adButtonOutLet = [[UIButton alloc] initWithFrame:CGRectMake(140*i, 0, 135, 40)];
[myButtonArray addObject:adButtonOutlet];
....
Then in you action method, set the right color:
for (UIButton* b in myButtonArray){
if(b.tag == sender.tag){
[self setSelectedColor:YES forButton:b];
// Do what you want here
}
else{
[self setSelectedColor:NO forButton:b];
}
}
With:
-(void)setSelectedColor:(BOOL)selected forButton:(UIButton)button{
if(selected){
sender.backgroundColor=UIColorFromRGB(0x000000) ;
[sender setTitleColor:UIColorFromRGB(0x179d95) forState:UIControlStateNormal];
}
else{
[sender setBackgroundColor:UIColorFromRGB(0X272c2f)];
[sender setTitleColor:UIColorFromRGB(0x969696)forState:UIControlStateNormal];
}
}
Apply state vise( Normal,Selected ) title color of button.
Just persist a selected button reference as weak.
while user clicked on button set that button state as selected instead normal.
Change last selected button state Normal instead Selected.
Check out below code that will be help you
UIButton *selectedButton;
-(void)adButtonAction:(UIButton*)sender
{
UIButton *tempButton = sender;
if (selectedButton && selectedButton!=tempButton)
{
[selectedButton setSelected:NO];
}
[tempButton setSelected:YES];
selectedButton = tempButton;
}
Question: How do I target one of many dynamically created UIButtons so I can change its properties?
Background: I have a storyboard with a UIViewConroller. When this UIVC loads a UIScrollView is added, to which a UIImageView is placed that has an exhibition floor plan. Each exhibitor has an entry in a database that contains its location on the floor plan. When the UIVC is loaded a loop is run for all exhibitors and each one has a UIButton drawn on the UIIV. When a UIB is clicked the button background colour is changed (to confirm which exhibitor has been selected) and a UIAlertView is shown with information about that exhibitor. When the UIAV's 'cancel' (ok) button is pressed the UIAV closes and the background highlight colour that was applied previously should be removed but here is where I am having the problem. I am unable to target the UIButton so I can change its background colour.
What I have tried so far: As each button is created I am giving it a tag and a title and recording both in an array. When the 'cancel' button is pressed on the UIAlertView I have tried checking the tag in the array but I still cannot actually target the UIButton.
I was thinking something like this:
// obviously not correct syntax but the kind of thing I want
[exhibitorBtn(tag) setBackgroundColor:[UIColor greenColor]];
So, say I have 12 UIButtons all called exhibitorBtn but with different titles and tags:
Object ----- Name ---------- Title -------- Tag
UIButton -- exhibitorBtn -- Glaxo ------ 1
UIButton -- exhibitorBtn -- Porsche --- 2
UIButton -- exhibitorBtn -- Rolex ------- 3 < How would I target that button's properties?
Edit - added the code that creates the buttons just to clarify:
for (NSDictionary *dict in exhibitorStandArray) {
NSInteger currentPosition = [exhibitorStandArray indexOfObject:dict];
NSLog(#"Position in array = %li", (long)currentPosition);
if (![dict[#"locCoords"] isEqual: #""]) {
NSInteger buttonTag = [exhibitorStandArray indexOfObject:dict];
NSString *standNo = dict[#"locStandNo"];
NSMutableDictionary *buttonDictionary = [[NSMutableDictionary alloc] init];
[buttonDictionary setObject:[NSNumber numberWithInteger:buttonTag] forKey:#"buttonTag"];
[buttonDictionary setObject:standNo forKey:#"buttonStandNo"];
[_masterButtonList addObject:buttonDictionary];
NSString *locCoords = dict[#"locCoords"];
NSArray *tempArray =[locCoords componentsSeparatedByString:#","];
tlcTop = [[tempArray objectAtIndex:0] integerValue];
tlcLeft = [[tempArray objectAtIndex:1] integerValue];
brcTop = [[tempArray objectAtIndex:2] integerValue];
brcRight = [[tempArray objectAtIndex:3] integerValue];
buttonWidth = brcRight - tlcLeft;
buttonHeight = brcTop - tlcTop;
testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
testBtn.frame = CGRectMake(tlcTop, tlcLeft, buttonHeight, buttonWidth);
testBtn.titleLabel.text = standNo;
testBtn.tag = buttonTag;
NSLog(#"UIButton Title = %#", testBtn.titleLabel.text);
NSLog(#"UIButton Tag = %li", (long)testBtn.tag);
testBtn.titleLabel.hidden = YES;
[testBtn addTarget:self action:#selector(displayInfo:) forControlEvents:UIControlEventTouchUpInside];
[_buttonArray addObject:testBtn];
[_imageView addSubview:testBtn];
}
}
Why can't you just use viewWithTag:
UIButton * button = (UIButton *)[self.scrollView viewWithTag:tag];
Your code probably looks something like this:
for (int i = 0; i < 5; i++)
{
UIButton *exhibitorBtn = [[UIButton alloc] initWithFrame:etc..];
exhibitorButton.tag = i;
[scrollView addSubview:exhibitorBtn];
}
Just change the loop so every button will be added to an array, too. Declare a NSMutableArray as a property: #property (strong, nonatomic) NSMutableArray *buttonsArray;
And #synthesize and initialise it in your init method. buttonsArray = [[NSMutableArray alloc] init]
Then, change the loop like I said above:
for (int i = 0; i < 5; i++)
{
UIButton *exhibitorBtn = [[UIButton alloc] initWithFrame:etc..];
exhibitorButton.tag = i;
[buttonsArray addObject:exhibitorBtn];
[scrollView addSubview:exhibitorBtn];
}
Finally, when you want to access the buttons:
for (int i = 0; i < [buttonsArray count]; i++)
{
UIButton *button = [buttonsArray objectAtIndex:i];
if (button.tag == 3) { // This is the button you wanted to target!
[button setHidden:YES];
}
}
Let's make it clear: you did set target and action of UIButton to controller's IBAction method and get the button as sender argument. Now you show UIAlertView and after it is dismissed, you want to send some message to that button, right?
Another method is to set delegate property for UIAlertView and respond to – alertView:clickedButtonAtIndex: delegate method. Trouble is that sender is lost at that point. You may use objc_setAssociatedObject to associate UIButton with UIAlertView and the retrieve it back when delegate method fires:
#import <objc/runtime.h>
static char myButtonKey = 0; // to use address as a key (value is irrelevant)
- (IBAction)buttonDidClick:(id)button
{
UIAlertView *alertView = <setup alert>;
[alertView setDelegate:self];
objc_setAssociatedObject(alertView, &myButtonKey, button, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
<show alert>;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIButton *thatButton = objc_getAssociatedObject(alertView, &myButtonKey);
<use thatButton>;
}
Try to create button in this way and add selector to them :
for (int i = 0; i < 5; i++)
{
UIButton *button = [[UIButton alloc] initWithFrame:CGRectZero];
button.tag = i;
[button addTarget:self
action:#selector(buttonPressedMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Show View" forState:UIControlStateNormal];
// add button to subview here
}
In method, just do whatever, you want to do :
- (void) buttonPressedMethod : (id) sender {
UIButton *selectedButton = (UIButton *)sender;
if (selectedButton.tag == 0) {
}
else if (selectedButton.tag == 1) {
}
else {
}
}
So basically I am making an API call to retrieve a list of Charities. I then place all this in an array and set UIButtons dynamically.
I then allow the user to select the charity and display a view with that index's data.
My loop is here;
for (int i = 0; i < [self.imageArray count]; i++) {
NSDictionary *listRoles = [self.imageArray objectAtIndex:i];
NSString *charityName = [listRoles objectForKey:#"name"];
NSString *charityDescription = [listRoles objectForKey:#"description"];
NSString *charityImage = [listRoles objectForKey:#"image"];
UIImage *pImage=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:charityImage]]];;
UIButton *button = [[UIButton alloc] initWithFrame:frame];
[button addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:pImage forState:UIControlStateNormal];
[button setTag:i];
[self.scrollView addSubview:button];
I then have a clicked method;
- (void)buttonClicked:(UIButton*)button
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
CharityProfileViewController *cpvc = [storyboard instantiateViewControllerWithIdentifier:#"CharityProfile"];
[self presentViewController:cpvc animated:YES completion:nil];
}
How can I retrieve the index, I know that I could set random tags for the UIButton but how would I still know which one?
You can set the tag value of button as
[button setTag:i+1];
then in Button Action
- (void)buttonClicked:(UIButton*)button
{
NSLog(#"Button Tag : %d",button.tag);
NSLog(#"Selected Index Object : %#",[self.imageArray objectAtIndex:button.tag-1]);
}
You can either retrieve the a tag for your button by button.tag or add your buttons to an array and use then [buttonsArray indexOfObject:button] in your buttonClicked: method
I am creating a small game with an interface that is quite similar to 4 Pictures 1 word. The current setup so far is as follows:
The user gets a 7 letter word generated at random.
There is an array which takes the 7 letters and then randomly populates them with other letters in 12 programatically created UIButtons:
for (int i=0; i< buttonCount; i++) {
int xpositiong = x + 37;
x = xpositiong;
isSeven ++;
restAt7 ++;
NSString *stringFromInt = [NSString stringWithFormat:#"%#",[arrayForRound objectAtIndex:i]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:#selector(buttonSelected:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:stringFromInt forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:#"helvetica" size:19];
button.tag = i+10;
_letterButton = button;
if (restAt7 == 7) {
x = 47;
}
if (isSeven <= 6) {
button.frame = CGRectMake(x,333,40,40);
}
else
{
button.frame = CGRectMake(x,370,40,40);
}
[self.view addSubview:button];
}
There is also a second area of Buttons however these are static and constitute as "the word". When one of the 12 letters are selected it takes the tag of the selected button and populates one of the corresponding "word" buttons.
-(void)buttonSelected : (UIButton *)sender
{
NSLog(#"sender %i", sender.tag);
UIButton *button = (UIButton *)[self.view viewWithTag:sender.tag];
button.hidden = YES;
if ([_buttonOne.titleLabel.text isEqualToString: #" "]) {
// NSLog(#"button is nil");
[_buttonOne setTitle:sender.titleLabel.text forState:UIControlStateNormal];
[_buttonOne setTag:button.tag];
}
else if ([_buttonTwo.titleLabel.text isEqualToString:#" "])
{
[_buttonTwo setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
else if ([_buttonThree.titleLabel.text isEqualToString:#" "])
{
[_buttonThree setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
else if ([_buttonFour.titleLabel.text isEqualToString:#" "])
{
[_buttonFour setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
else if ([_buttonFive.titleLabel.text isEqualToString:#" "])
{
[_buttonFive setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
else if ([_buttonSix.titleLabel.text isEqualToString:#" "])
{
[_buttonSix setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
else if ([_buttonSeven.titleLabel.text isEqualToString:#" "])
{
[_buttonSeven setTitle:sender.titleLabel.text forState:UIControlStateNormal];
}
}
Right! So here is my question. If the user decides they have selected the wrong letter and wish to remove that letter they can press one of the 7 buttons to delete that letter. However I dont know how to un-hide the corresponding button which was originally populated with the letter...
I am confident it has something to do with retaining the Tag of the selected button however because each of the 7 buttons is assigned with Tag's I am not sure how to go about doing it.
EDIT:
I'll post up the solution that has worked. Also all functions have been rewritten with loops.
-(void)buttonSelected : (UIButton *)sender
{
NSLog(#"sender %i", sender.tag);
UIButton *button = (UIButton *)[self.view viewWithTag:sender.tag];
button.hidden = YES;
for (int i = 0; i < _wordButtonsArray.count; i ++) {
UIButton *selectedButton = [_wordButtonsArray objectAtIndex:i];
if ([selectedButton.titleLabel.text isEqualToString:#" "]) {
[selectedButton setTitle:sender.titleLabel.text forState:UIControlStateNormal];
[selectedButton setTag:button.tag];
return;
}
}
[self checkIfAnswerIsFinished:sender];
}
- (IBAction)clearButton:(id)sender
{
UIButton *button = (UIButton *)[self.view viewWithTag:[sender tag]];
button.hidden = NO;
for (int i = 0; i < _wordButtonsArray.count; i ++) {
if (button == [_wordButtonsArray objectAtIndex:i]) {
[button setTitle:#" " forState:UIControlStateNormal];
for (int letterButtonsIndex = 0; letterButtonsIndex < _letterButtonsArray.count; letterButtonsIndex++) {
UIButton *letterButton = [_letterButtonsArray objectAtIndex:letterButtonsIndex];
if (button.tag == letterButton.tag) {
button.tag = i;
letterButton.hidden = NO;
}
}
}
}
}
Works like a charm!
It seems like one way to do this is to make an NSArray that has 7 spaces, each filled with either the tag of the source button or -1. If a user taps on a -1, do nothing. If it is a number, set that tagged item to visible.
Also, your code is terribly not DRY (Don't Repeat Yourself) - you should spend some time thinking about programming and how you could use data structures more nicely. If you want more definite advice, just ask in the comments and I'll edit. :)
I can think of a couple of ways to accomplish this.
Solution 1:
Add your 12 buttons (bottom section) to an NSArray so when the user presses one of the 7 buttons (top section) you can iterate through that array and compare the titles. Something like this:
for (UIButton *button in buttonsArray) {
NSString *buttonTitle = [button titleForState:UIControlStateNormal];
// I'm assuming here that you already have the touched button tile
if ([buttonTitle isEqualToString:touchedButtonTitle]) {
button.hidden = NO;
}
}
Solution 2:
Create an array of 7 elements where you can match the "word" buttons with the tags of your letter buttons. Something like this:
-(void)buttonSelected : (UIButton *)sender
{
NSLog(#"sender %i", sender.tag);
UIButton *button = (UIButton *)[self.view viewWithTag:sender.tag];
button.hidden = YES;
if ([_buttonOne.titleLabel.text isEqualToString: #" "]) {
// NSLog(#"button is nil");
[_buttonOne setTitle:sender.titleLabel.text forState:UIControlStateNormal];
[_buttonOne setTag:button.tag];
// you know this is object One. Insert tag at position zero (arrays are zero-based)
self.topButtonsArray insertObject:[NSNumber numberWithInt:sender.tag] atIndex:0];
}
.
.
.
Hope this helps!