Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove Buttons Dynamically with an Array
    primarykey
    data
    text
    <p>I have a view that has labels being dynamically added by the user. If the use would like to edit any of the labels, they press a button and all the labels get highlighted with a delete button and move button. (Editing is another bridge I’ll cross later).</p> <p>My issue is: What is the best way to turn the buttons on and off? I have a method that turns the buttons on… but I am at a loss as to how I turn them off when done editing. Do I need to tag my buttons and then just ‘hide them’? Or do I just remove them all totally? How do I parse all the buttons that are turned on then, turn them off. Do I need to put them in an array as well? The labels are tagged with unique numbers so I know which label is which. </p> <p>Any thoughts? Guidance? If I am doing it all wrong please tell me. </p> <p>Here is a couple methods I have: </p> <pre><code>- (void) showEditableText { // Parse the array of labels if(textArray.count &gt; 0){ for(UILabel *label in textArray){ //Add Delete Button UIImage * delButtonImage = [UIImage imageNamed:@"GUI_Delete.png"]; UIButton * delThisButton = [[UIButton alloc] initWithFrame:CGRectMake(label.frame.origin.x - delButtonImage.size.width, label.frame.origin.y - delButtonImage.size.height, delButtonImage.size.width, delButtonImage.size.height)]; [delThisButton setBackgroundImage:delButtonImage forState:UIControlStateNormal]; [delThisButton addTarget:self action:@selector(deleteThisLabel:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:delThisButton]; //Add a move button UIImage * moveButtonImage = [UIImage imageNamed:@"GUI_Move.png"]; UIButton * moveThisButton = [[UIButton alloc] initWithFrame:CGRectMake((label.frame.origin.x + label.frame.size.width + moveButtonImage.size.width), label.frame.origin.y - moveButtonImage.size.height, moveButtonImage.size.width, moveButtonImage.size.height)]; [moveThisButton setBackgroundImage:moveButtonImage forState:UIControlStateNormal]; [moveThisButton addTarget:self action:@selector(moveThisLabel:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:moveThisButton]; //Make the text highlighed label.highlighted = YES; label.backgroundColor = [UIColor colorWithRed:203/255.0f green:230/255.0f blue:239/255.0f alpha:1]; label.highlightedTextColor = [UIColor redColor]; } } } - (void) doneEditingText { if(textArray.count &gt; 0){ for(UILabel *label in textArray){ //THIS IS WHERE I AM STUCK? WHAT DO I DO? label.highlighted = NO; label.backgroundColor = [UIColor clearColor]; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload