Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ionini

macrumors newbie
Original poster
Aug 29, 2011
13
0
So I have this application where I want to control an infinite number of UIButtons, for example I want to tell the UIButton x (x bing an int) to go to where the UIButton x-1 is.
Any ideas?
 
You could use the .tag property.

Tags are ints. By default, every view has a tag of 0, but you could assign a different tag to each button as it's created. Interface Builder also allows you to assign tags, if you'll be making your buttons that way. There are methods you can use to say find a button with a certain tag in a certain view. Check the documentation to find the exact method name.
 
You could use the .tag property.

Tags are ints. By default, every view has a tag of 0, but you could assign a different tag to each button as it's created. Interface Builder also allows you to assign tags, if you'll be making your buttons that way. There are methods you can use to say find a button with a certain tag in a certain view. Check the documentation to find the exact method name.

Ok i get it, but (im asking this coz i cant find it) how do i use this with the .center?
 
Ok i get it, but (im asking this coz i cant find it) how do i use this with the .center?

Your question didn't mention center. Center is a different attribute and has no relation to the tag. Describe what it is you are trying to accomplish.

EDIT: I reread your question. You want to move one button the location of another. I see ArtOfWarfare described it for you. Remember that views are layered, so moving something may place it underneath another view. I you are looking for more than that, then describe it in detail.
 
Last edited:
Ok i get it, but (im asking this coz i cant find it) how do i use this with the .center?

Code:
[(UIView) viewWithTag:(int)].center

Inserting the superview of the button in place of (UIView) and the tag of the button for (int) would return a CGPoint that represents the center of the button.

(Also, I second what xStep said just before me.)
 
Code:
[(UIView) viewWithTag:(int)].center

Inserting the superview of the button in place of (UIView) and the tag of the button for (int) would return a CGPoint that represents the center of the button.

(Also, I second what xStep said just before me.)

sorry, i said i want it to go where the other button was.

----------

Code:
[(UIView) viewWithTag:(int)].center

Inserting the superview of the button in place of (UIView) and the tag of the button for (int) would return a CGPoint that represents the center of the button.

(Also, I second what xStep said just before me.)
OK. thx, but.. i dont know what to put there, could you give me an example?
 
OK. thx, but.. i dont know what to put there, could you give me an example?

The superview is the view that contains the buttons. Read the UIView documentation and I think you can figure out what to put there. Start at the top in the Overview and then see the superview property.
 
The superview is the view that contains the buttons. Read the UIView documentation and I think you can figure out what to put there. Start at the top in the Overview and then see the superview property.

so this is what i got
Code:
 [_view viewWithTag:1].center
it just fail with: "Undefined symbols for architecture i386:
"_OBJC_IVAR_$_UIViewController._view", referenced from:
-[QuineceViewController cambioDePosicion] in QuineceViewController.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status"
any help?
 
so this is what i got
Code:
 [_view viewWithTag:1].center
it just fail with: "Undefined symbols for architecture i386:
"_OBJC_IVAR_$_UIViewController._view", referenced from:
-[QuineceViewController cambioDePosicion] in QuineceViewController.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status"
any help?

What is _view? Where does it come from? How is it defined?

This is why you'll see people post chunks of code; so that others can understand the context and perhaps even see and describe the error. Use the CODE tag in this forum so that your code gets displayed properly.
 
What is _view? Where does it come from? How is it defined?

This is why you'll see people post chunks of code; so that others can understand the context and perhaps even see and describe the error. Use the CODE tag in this forum so that your code gets displayed properly.
Code:
- (void)cambioDePosicion{
    UIView *view;
    [view viewWithTag:1].center = CGPointMake(Button2.center.x , Button2.center.y);
    
}
 
Code:
- (void)cambioDePosicion{
    UIView *view;
    [view viewWithTag:1].center = CGPointMake(Button2.center.x , Button2.center.y);
    
}

Well, first, that won't work since view isn't instantiated (allocated & initialized). In this case, view is nil.

Second, that view isn't _view from your error that you posted.
 
Well, first, that won't work since view isn't instantiated (allocated & initialized). In this case, view is nil.

Second, that view isn't _view from your error that you posted.

so yeah... i have no idea what to do and th code was
Code:
- (void)cambioDePosicion{
    [_view viewWithTag:1].center = CGPointMake(Button2.center.x , Button2.center.y);
    
}
 
so yeah... i have no idea what to do and th code was
Code:
- (void)cambioDePosicion{
    [_view viewWithTag:1].center = CGPointMake(Button2.center.x , Button2.center.y);
    
}

thank you very much for your help.
i finally made it.
here is the code
Code:
    [self.view viewWithTag:1].center = CGPointMake(Button2.center.x , Button2.center.y);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.