Array of objects?

Discussion in 'iOS Programming' started by ionini, Sep 4, 2011.

  1. ionini macrumors newbie

    Joined:
    Aug 29, 2011
    #1
    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?
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    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.
     
  3. ionini thread starter macrumors newbie

    Joined:
    Aug 29, 2011
    #3
    Ok i get it, but (im asking this coz i cant find it) how do i use this with the .center?
     
  4. xStep, Sep 4, 2011
    Last edited: Sep 4, 2011

    xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #4
    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.
     
  5. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #5
    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.)
     
  6. ionini thread starter macrumors newbie

    Joined:
    Aug 29, 2011
    #6
    sorry, i said i want it to go where the other button was.

    ----------

    OK. thx, but.. i dont know what to put there, could you give me an example?
     
  7. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #7
    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.
     
  8. ionini thread starter macrumors newbie

    Joined:
    Aug 29, 2011
    #8
    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?
     
  9. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #9
    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.
     
  10. ionini thread starter macrumors newbie

    Joined:
    Aug 29, 2011
    #10
    Code:
    - (void)cambioDePosicion{
        UIView *view;
        [view viewWithTag:1].center = CGPointMake(Button2.center.x , Button2.center.y);
        
    }
    
     
  11. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #11
    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.
     
  12. ionini thread starter macrumors newbie

    Joined:
    Aug 29, 2011
    #12
    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);
        
    }
    
     
  13. ionini thread starter macrumors newbie

    Joined:
    Aug 29, 2011
    #13
    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);
    
     

Share This Page