Note that there are some explanatory texts on larger screens.

plurals
  1. POReusing class best practice
    text
    copied!<p>My UIView (<strong>ClassA</strong>) has a button that when pressed shows another UIView (<strong>ColorClass</strong>) with 3 buttons that allows a user to select a color. The color that is selected is passed back to <strong>ClassA</strong> so that it can be worked with. It is also passed to a <em>Storage</em> (a singleton) class for saving the selected color. </p> <p>This works great, but now, I need a second unrelated class <strong>ClassB</strong>, to have same functionality. But when I call the same method I normally call in <strong>ClassA</strong> from inside <strong>ClassB</strong>, <strong>ClassA</strong> is the one that is updated. </p> <p>How can I make <strong>ColorClass</strong> more agnostic to the calling class? I am still learning so if someone could help point me in the right direction that would be great.</p> <p><strong>ClassA</strong></p> <pre><code>- (void) showColorPicker{ CGRect colorPickerFrame = CGRectMake(150, 100, 237, 215); colorPicker= [[ColorClass alloc] initWithFrame:colorPickerFrame]; colorPicker.vc = self; [self.view insertSubview:colorPicker aboveSubview:self.view]; } - (void) setTheButtonColor : (int) c { Sufficient to say this just changes the buttons background color selected from a list of colors } </code></pre> <p><strong>ColorClass</strong> </p> <p>When a selected color is pressed, I call this method that messages ClassA with the color.</p> <pre><code>- (void) buttonPressed : (id) sender { [self.vc setButtonColor:[sender tag]]; [myStorage setButtonColor:[sender tag]]; } </code></pre> <p><img src="https://i.stack.imgur.com/LheLp.png" alt="Layout"></p>
 

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