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 3222450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:59:33+00:00 2026-05-17T15:59:33+00:00

MyViewController has one UIButton and another MainViewController use MyViewController. but MainViewController can’t change UIButton

  • 0

MyViewController has one UIButton and another MainViewController use MyViewController.

but MainViewController can’t change UIButton title in MyViewController.

also, in MyViewController only change UIButton title in viewDidLoad method.

What’s wrong?

MyViewController

@interface MyViewcontroller : UIViewController {
    IBOutlet UIButton *imageButton;
}

@property (nonatomic, retain) UIButton *imageButton;

@implementation MyViewcontroller : UIViewController {
@synthesize imageButton;
    - (void)viewDidLoad { // can change button title
        [imageButton setTitle:@"buttonTitle" forState:UIControlStateNormal]
    }

    - (void)setButtonTitle { // can't change button title
        [imageButton setTitle:@"buttonTitle" forState:UIControlStateNormal];
    }
}

MainViewController

@implementation MainViewController : UIViewController {
@synthesize scrollView;
    - (void)viewDidLoad { // can't change button title
        MyViewcontroller *myView = [[MyViewcontroller alloc] initWithNibName:@"MyViewcontroller" bundle:nil];
        [myView.imageButton setTitle:@"ddd" forState:UIControlStateNormal];
        [scrollView addSubview:myView.view];
        [myView release], myView = nil;
    }
}
  • 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-17T15:59:33+00:00Added an answer on May 17, 2026 at 3:59 pm

    It happens because the outlets don’t get wired until after the view is loaded, and the view doesn’t get loaded until after it gets called for the first time (it’s lazy loading). You can fix this very easily by just ensuring that you always load the view first. However, you might want to reconsider your design and make the button title dependent on some other item that’s not part of the view hierarchy.

    For example, if you re-order your calls, it will work:

    MyViewcontroller *myView = [[MyViewcontroller alloc] initWithNibName:@"MyViewcontroller" bundle:nil];
    [scrollView addSubview:myView.view]; // view is loaded
    [myView.imageButton setTitle:@"ddd" forState:UIControlStateNormal]; // imageButton is now wired
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't just do [myViewController dismissModalViewControllerAnimated:YES]; [myViewController presentModalViewController:nextModalViewController animated:YES]; one after the other, because
I'm at a loss! It's one of those pesky bugs that happens only under
Lets say I have a view, myView, a view controller, myViewController, and some sort
I have a project that generates applications for two targets. One of the targets
One of my users is reporting a crash on his device, an iPhone 3GS.
I've got a UITabController. One of the tabs is a UINavigationController. Pushing and popping
I load view controllers all the time in the following format: -(void)loadSelectUser { MyViewController
I want to use a modal view ( UIViewController ) as a normal view,
I am trying to detect touches, but the touchesBegan method is not being called.
I have something like this: myViewController = [[MyViewController alloc] initWithNibName:@MyView bundle:nil]; [mainCanvas addSubview: myViewController.view];

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.