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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:21:22+00:00 2026-05-11T11:21:22+00:00

I am new to the iPhone SDK and am trying to create 3 views

  • 0

I am new to the iPhone SDK and am trying to create 3 views and switch between them. Data will come from a server and I will basically be showing 1 view and caching the other two. So far I am just trying to create a view and display it at run-time. My code is listed below. It shows only a blank screen and I think I am missing a key concept. Any Help?

#import <UIKit/UIKit.h> #import 'ImageViewController.h' @interface Test5ViewController : UIViewController  {     IBOutlet UIView *rootView;     ImageViewController *curImage;     ImageViewController *nextImage;     ImageViewController *prevImage; }  @property(nonatomic,retain) IBOutlet UIView *rootView; @property(nonatomic,retain) ImageViewController *curImage; @property(nonatomic,retain) ImageViewController *nextImage; @property(nonatomic,retain) ImageViewController *prevImage;  @end 

and

- (void)loadView  {      self.curImage = [[ImageViewController alloc]initWithNibName:@'ImageView' bundle:[NSBundle mainBundle]];     UIImage *pic = [UIImage imageNamed:@'baby-gorilla.jpg'];     [self.curImage assignImage:pic];     self.rootView = self.curImage.view;  } 

and

#import <UIKit/UIKit.h>   @interface ImageViewController : UIViewController  {     IBOutlet UIImageView *image; }  -(void)assignImage:(UIImage *)screenShotToSet;   @property(nonatomic,retain) IBOutlet UIImageView *image;  @end 
  • 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. 2026-05-11T11:21:22+00:00Added an answer on May 11, 2026 at 11:21 am

    Welcome to the iPhone SDK!

    In general, there are two ways to get any view displayed.

    First, and most commonly, you use a NIB file created by the Interface Builder. This is usually the easiest way to get started and I would recommend it for what you’re trying to do here. It’s too lengthy to describe all the steps you need to do for what you have here, but basically start in xcode by creating a new file and selecting ‘user interfaces’ and choose View XIB. This will create a basic NIB file (they’re called NIBs rather than XIBs for historical reasons). The first step in interface builder is to change the class name of the ‘File’s Owner’ to your UIViewController subclass (Test5ViewController). You can then drop anything that IB will allow into the view window or even replace the pre-supplied view object with one of your own. And here’s the trick: make sure the view outlet (supplied by the UIViewController superclass) is connected to a view. Once this is done, this view will be automatically loaded when your NIB is loaded. You can then just put your UIViewController subclass (Test5ViewController) in your MainWindow.xib NIB file to get it automatically loaded, and you’re in business.

    Now, the way you’re doing it here is the second way. Some people like to code this way all the time and not user interface builder. And while it’s definitely necessary sometimes and always more flexible, it makes you understand what is happening a bit better. There may be other things, but the main thing you’re missing is that in your code above, you have nothing that is adding your view into the view hierarchy. You need to check first that you have an UIApplicationDelegate subclass and it needs to load your ‘root’ UIViewController class. All initial project creation types in xcode do this (except Window-based application). It is code like:

    [window addSubview:rootController.view]; 

    Once this is done, if your view controller wasn’t loaded by the NIB (described briefly above), your loadView method will be called, expecting you to build your own view hierarchy. Above, you created the view(s), but failed to put them in a hierarchy. You need something like:

    [self.view addSubview:curImage.view]; 

    No view will be rendered until added to the view hierarchy. Make sure to look up the UIView class in the documentation and understand the variety of ways to add and remove views to the view hierarchy.

    A couple things I should warn you about: * your code above is leaking. You need to review how objective-C properties work. There’s lots on this site about it. More than I have time to write about here. * don’t create a rootView property in the case you have here. There already is one in the superclass (UIViewController). It’s just ‘view’. Use that for saving your root view.

    I hope this helps you get started. It can be bewildering at first, but you’ll soon get it going! I recommend building and rewriting and rebuilding a lot of sample code before you do your ‘real’ application. The SDK has many great samples.

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

Sidebar

Related Questions

I am new to Objective C and the iPhone SDK, and am trying to
HTF? i'm new to the iphone SDK. for a navigationbar and uitable (from the
How do i put a swipe gesture in the new iPhone SDK? I'm trying
According to this post on Daring Fireball a new iPhone SDK Agreement release in
I am new to iPhone SDK. I am using butting in my NIB file.Here
I am new to iPhone SDK.I am printing each and every array in console.No
i'm new at IPhone SDK Developing and now i need some help. I have
im new to the iPhone SDK and development. I work for a company that
Preface : I am new to the iPhone SDK, Obj-C, Interface Builder and Cocoa.
I'm new to xcode and the iphone sdk. I've been working with the view-based

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.