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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:16:19+00:00 2026-06-08T19:16:19+00:00

I have a UIViewController with some controllers and some views. Two of these views

  • 0

I have a UIViewController with some controllers and some views. Two of these views (Grid Cell) are other nibs. I’ve got outlets from the Grid Cells to File’s Owner, but they aren’t loaded automatically.

So I try to override GridCell.m‘s initWithCoder.
This starts an infinite loop.

I know it’s possible to just override initWithFrame and add the subview from code, but this is not what I want. I want to be able to move the view around in Interface Builder and have Xcode initialize the view with the right frame.

How do I go about achieving this?

EDIT 1

I’m trying to get it working with the help of Alexander. This is how I’ve now got it set up:
MainView has UIView with a Custom class set as GridCell. It got an outlet in the MainView/File’s Owner.

Pic 1

Removed all init-code from GridCell.m and set up an outlet to my custom class

Pic 2

Pic 3

The MainView don’t still display the GridCell though. There’s no error, just a lonely, empty space where the red switch should be. What am I doing wrong?

I’m very close to just doing this programmatically. I would love to learn how to this with nibs 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-06-08T19:16:20+00:00Added an answer on June 8, 2026 at 7:16 pm

    Loading the nib causes initWithCoder to be called again, so you only want to do so if the subclass currently doesn’t have any subviews.

    -(id)initWithCoder:(NSCoder *)aDecoder {
        self = [super initWithCoder:aDecoder];
        if (self) {
            if (self.subviews.count == 0) {
                UINib *nib = [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
                UIView *subview = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0];
                subview.frame = self.bounds;
                [self addSubview:subview];
            }
        }
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do some simple animation. I have a UIViewController that has two
In my application, I have two View Controllers - a UIViewController and UITableViewController. Now,
I have an app where I subclass UIViewController and add some characteristics to it,
I have some codes as below #import <UIKit/UIKit.h> @interface ViewMoreSettingController : UIViewController < UITableViewDelegate,
I have a uiviewcontroller with two properties: trackName and playerObject. PlayerObject also has a
I'm new at iOS development. I have two table views and a content detail
I have a UIViewController that manages the display of some data. When the user
I have a tab bar controller and some nav controllers containing view controllers. In
I have two view controllers. The CardWallet View Controller is my table view. Then
I have a UITabBarController with two UIViewControllers f.e All Messages, Favourite Messages. For some

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.