开发者

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 obje开发者_如何学Goct 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜