Using a UIButton instead of a UISegmentedControl to control a socket app
<p>I found this piece of code and it works great except I want to use a UIButton instead of a UISegmentedControl. See the code below</p>

<pre><code>- (IBAction)ToggleLight:(id)sender {

    UISegmentedControl *button = ((UISegmentedControl*)sender);
    long tag = button.tag;

    NSString *response  = [NSString stringWithFormat:@"P%ld%@", tag , button.selectedSegmentIndex?@"L" : @"H"];
    NSData *data = [[NSData alloc] initWithData:[response dataUsingEncoding:NSASCIIStringEncoding]];
    [_outputStream write:[data bytes] maxLength:[data length]];

}
</code></pre>

<p>I am pretty sure I need to change the first line to </p>

<pre><code>UIButton *button = ((UIButton*)sender);
</code></pre>

<p>but I am confused by what to put instead of "selectedSegmentIndex" for a UIButton to have the same effect? I am new to this so I maybe going the wrong direction completely. Any help is greatly appreciated!</p>

<p>Here is a <a href="http://bitcows.com/?p=249" rel="nofollow">link</a> to where I got the code and the tutorial I am working from.</p>