Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4108890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:43:09+00:00 2026-05-20T21:43:09+00:00

I’m new to Objective-C, and I’m trying to create an app with two buttons

  • 0

I’m new to Objective-C, and I’m trying to create an app with two buttons that toggle off and on in tandem. I’ve handled the button states (images for on and off) in Interace Bulder, but I’m having trouble figuring out exactly how to write the logic in Xcode.

Here are the conditions I need to fulfill:

-When neither button is on, either button may be turned on.

-When button1 is on, and button2 is clicked, button1 turns off, and button 2 turns on.

-When button2 is on, and button1 is clicked, button2 turns off, and button 1 turns on.

-When button1 is on and button1 is clicked, nothing happens.

-When button2 is on and button2 is clicked, nothing happens.

I’ve been using BOOL to try and work out the logic, but it’s just not happening for me. Does anyone have an idea of how to do this?

The buttons were added programatiaclly, so the simple code looks like this in the .h file:

in .h:

#import <UIKit/UIKit.h>
@interface Profile_Settings_PageViewController : UIViewController {


IBOutlet UIButton *Button1;
IBOutlet UIButton *Button2;


BOOL ButtonSelected;
}

@property (nonatomic, retain) UIButton *Button1;
@property (nonatomic, retain) UIButton *Buton2;


-(IBAction) ButtonTouched:(id)sender;
@end

then the .m file:

#import "Profile_Settings_PageViewController.h"

@implementation Profile_Settings_PageViewController
@synthesize Button1;
@synthesize Button2;



-(IBAction) ButtonTouched:(id)sender
{

if (ButtonSelected == 0)
{
    [Button1 setSelected: NO];
    [Button2 setSelected: NO];
    ButtonSelected = 1;
}

else if (ButtonSelected == 1)  
{
    [Button1 setSelected: YES];
    [Button2 setSelected: YES];

    ButtonSelected = 0;

}

}
- (void)viewDidLoad {

[super viewDidLoad];

ButtonSelected == 0;
}

- (void)dealloc {
  [Button1 release];
  [Button2 release];

  [super dealloc];
}

@end

The issue I’m having is where the if statement begins. I’m not sure how to point to the specific buttons for the logic. I know what’s there now is not correct both because it applies to both buttons, and because the logic is wrong, which creates problems when writing the conditional statements. I’m not sure how to fix it though…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:43:10+00:00Added an answer on May 20, 2026 at 9:43 pm

    If your image states are for NORMAL and SELECTED, create two buttons with outlets, tag them 1 & 2 respectively, and in your button action method:

    Start with button 1 selected, button 2 normal.

    - (IBAction)buttonAction:(UIButton*)sender 
    {
        if (sender.selected)
            return;
        if (sender.tag == 1)
        {
            button1.selected = !button1.selected;
            button2.selected = !button1.selected;
        }
        else if (sender.tag == 2)
        {
            button2.selected = !button2.selected;
            button1.selected = !button2.selected;
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.