当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Adding my first view to a window based application

问题描述:

I'm beginner with iPhone and want to know how to add a view in a window based application.

I crate the application, then I added the ViewControler+XIB to my project.

I include the .h file in both AppDelegate-Files.

Then I create a object of the View "StartViewController" with

StartViewController *startView;

and add the property in the AppDelegate.h file:

@property (nonatomic, retain) StartViewController *startView;

In the AppDelegate.m I add:

@synthessize startViewController

and in the application method:

[window addSubview:startViewController.view];

But it doesn't appear when I start the application, what I forgot?

网友答案:

You're not allocating or initializing it anywhere that I can see. From what you're saying, it seems like you need to put in a

startView = [[StartViewController alloc] initWithNibName:@"xib filename without dot xib" bundle:nil];

If this doesn't sound right, it may instead be that you aren't setting Interface Builder up right. How is the main window linking to this XIB / view controller of yours? Do you have it referenced as a view?

网友答案:

I'm beginner with iPhone and want to know how to add a view in a window based application

STEP 1: Open Xcode Create New Project Select Window Based Application.Name is Some x that is display two files xappdeligate.h and xappdelegate.m.

Step 2: in project click right button add ui view controller name is FirstViewController that is displays FirstViewController .h , FirstViewController .m

Step 3: In xappdeligate.h we have to write

   FirstViewController *viewController;

define Property:

@property(nonatomic,retain)FirstViewController *viewController;

Step: 4

In xappdelegate.m we have to synthesize to them

@synthesize viewController;

allocate thememory:

   viewController = [[FirstViewController alloc]init];

add view to the window:

[self.window addSubview:FirstViewController.view];

Step: 5

We should compulsary release the memory for this in

-(void)dealloc
{
[window release];
[viewController release];

}

this is simple way to add view to the window.

Ur's Raffi 37...

网友答案:

Just connect the view with interface builder by dragging.

and still if you can't connect , here is link where a number of applications are provided to learn iPhone applications.

分享给朋友:
您可能感兴趣的文章:
随机阅读: