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

  • Home
  • SEARCH
  • 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 7045533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:32:31+00:00 2026-05-28T02:32:31+00:00

I run into a small problem (Not surprisingly, ’cause I’ve just started with xcode).

  • 0

I run into a small problem (Not surprisingly, ’cause I’ve just started with xcode). I tried to solve it with if-statemens, but they were clearly the wrong way to go.

Here is what I am trying to do: In the first ViewController I have for example 4 Buttons. If the user presses the first button he gets to ViewController2 and the label says “You pressed the first button”. If the user presses the second button he gets to ViewController2 and the label says “You pressed the second button” and so on.

I tried to solve it with Tag Statements, like:
FirstViewController.m

 - (IBAction)switch:(id)sender;

 {
 UIButton *buttonPressed = (UIButton *)sender;
SecondViewController *second =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
second.buttonTag  = buttonPressed.tag;
[self.navigationController pushViewController:second animated:YES];
(button.tag = 9001);


 - (IBAction)switch2:(id)sender2;

 {
 UIButton *buttonPressed = (UIButton *)sender2;
SecondViewController *third =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:third animated:YES];
second.buttonTag  = buttonPressed.tag;
[self.navigationController pushViewController:third animated:YES];
(button2.tag = 9002);

And here what I did in SecondViewController.m

- (void)viewDidLoad
 {
[super viewDidLoad];

if (buttonTag == 9001) {
    self.label1.text = [[NSString alloc] initWithFormat:@"Radnomtext"];
    self.label2.text = [[NSString alloc] initWithFormat:@"Randomtext"];
    self.label3.text = [[NSString alloc] initWithFormat:@"Randomtext?"];

if (buttonTag == 9002) {
    self.label1.text = [[NSString alloc] initWithFormat:@"Radnomtext2"];
    self.label2.text = [[NSString alloc] initWithFormat:@"Randomtext2"];
    self.label3.text = [[NSString alloc] initWithFormat:@"Randomtext2?"];

He always gives me the labels from ButtonTag 9001 – Someone any idea why?

  • 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-28T02:32:32+00:00Added an answer on May 28, 2026 at 2:32 am

    Here is a handy little trick for you: tags.

    Every UIView can have a property tag. It is a simple integer, and you can assign it in code (button.tag = 456;) or in Interface Builder. In your switch method, simply use:

    -(IBAction)switch:(id)sender {
       UIButton *buttonPressed = (UIButton *)sender;
       // create the second view controller, e.g.
       SecondViewController *secondViewController = [[SecondViewController alloc] init];
       // it should have an NSInteger @property e.g. "buttonTag"
       secondViewController.buttonTag  = buttonPressed.tag
       [self.navigationController 
           pushViewController:secondViewController animated:YES];
       // if not using ACT: [secondViewController release];
    }
    

    So just to make sure: your statement

    it is a no go to pass properties or values from one to another view controller

    is completely wrong. If the new view controller has a @property (which you define in the .h-file and @synthesize in the .m-file), you can simply assign these properties before pushing the new view controller. That’s what we did in the above code snippet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've run into a weird problem. Frame 1 contains a small preloader, and when
I'm developing a small game in Java and I have run into a problem
I'm building a small website with JQTouch and the first problem I've run into
I've run into a small problem using the WPF RibbonControl (October 2010 version). My
Okay, im relearning php for a small home project and run into a problem
I've run into a small problem, Ive got a page full of anchor tags
Im building a small webshop and have run into a problem. The company which
I've just started checking out WebMatrix, and am running into a problem. I performed
Possible Duplicate: Java AES Encrypt Entire String I've run into a small problem. For
I am creating a small Yahtzee game and i have run into some regex

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.