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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:03:40+00:00 2026-05-20T12:03:40+00:00

I am starting a multiview app with two views: NewGame and Players. I thought

  • 0

I am starting a multiview app with two views: NewGame and Players. I thought I was setting everything up properly, but apparently not.

MainViewController.h

#import <UIKit/UIKit.h>

@class NewGame; @class Players;

@interface MainViewController : UIViewController {
    IBOutlet NewGame *newGameController;
    IBOutlet Players *playersController;
}

-(IBAction) loadNewGame:(id)sender;
-(IBAction) loadPlayers:(id)sender;

-(void) clearView;

@end

MainViewController.m

#import "MainViewController.h"
#import "NewGame.h"
#import "Players.h"

@implementation MainViewController

-(IBAction) loadNewGame:(id)sender {
    [self clearView];
    [self.view insertSubview:newGameController atIndex:0];
}

-(IBAction) loadPlayers:(id)sender {
    [self clearView];
    [self.view insertSubview:playersController atIndex:0];
}

-(void) clearView {
    if (newGameController.view.superview) {
        [newGameController.view removeFromSuperview];
    } else if (playersController.view.superview) {
        [playersController.view removeFromSuperview];
    }
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [self loadNewGame:nil];
    [super viewDidLoad];
}

A couple of images…

https://i.stack.imgur.com/GwXMa.png
https://i.stack.imgur.com/XHktH.png

  • 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-20T12:03:40+00:00Added an answer on May 20, 2026 at 12:03 pm

    Views are objects that represent what appears on screen. View controllers are objects that perform application logic relating to those views. A view hierarchy is a collection of views. You are attempting to add a view controller to a view hierarchy as if it were actually a view.

    Roughly speaking, you should have one view controller for every “screen” of your app. This view controller can manage any number of views. Its main view is accessible through its view property.

    A quick fix to get your application operational would be to add the main view of your view controllers instead of the view controllers themselves. So, for example, this:

    [self.view insertSubview:playersController atIndex:0];
    

    …would become this:

    [self.view insertSubview:playersController.view atIndex:0];
    

    Having said that, this is not a good solution long-term, and you should investigate a more structured way of organising transitions from view controller to view controller. UINavigationController is a good option for beginners.

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

Sidebar

Related Questions

Starting to learn Canvas and have two classes so far (main one to call
Starting with a list of objects containing two parameters notional and currency, how can
Starting a new rails project and we have a well-thought-out color palette, and want
Starting the development of my android app,that uses Maps API, I didn't know that
Starting a project, and this irriating me. I think the code is okay, but
Starting with an app already in development, I have carried out the instructions in
Starting using werkzeug, i try to map urls (from a file urls.py) to views
Starting iOS development, I wish to implement handwriting recognition in my app. I did
Starting with iOS 5, there are two notification styles: banner and alert (the old
Starting to develop my first Ruby on Rails app with postgresql on Ubuntu. I

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.