views:

10670

answers:

4

I want to make a really simple iphone app: one screen with a single button... when the button is tapped a new screen appears. That's it. No animations, nothing,

I've tried endlessly to make the NavBar sample project do this... and it works but only if I use a UINavigationController with a table that I can tap etc. I've tried all the skeleton projects in XCode too.

I thought I was done when I did this:

[[self navigationController] presentModalViewController:myViewController animated:YES];

But I couldn't do it without the UINavigationController. I just want a simple example.

Thanks so much!

+4  A: 

One way you could do this is to create a new UIView and then when the button is pressed add that new UIVIew as a subview, therefore making it what you see.

If you make the new view its own subclass of UIView you would do something like this.

LoginView *login = [[LoginView alloc] initWithFrame: rect];
[mainView addSubview: login];
kdbdallas
A: 

The correct way to do this is set up your project with a UINavigationController. In your root view controller, add your button in the view controllers's view. Then in viewDidLoad, register for UIControlEventTouchUpInside events from you button. Then, in your event callback, call:

[self.navigationController pushViewController:[[[SecondViewControllerClass alloc] initWithNib:nibName bundle:nil] autorelease]];

What kdbdallas suggested will work, but you won't get the nice sliding effects, nor will the navigation bar automatically change and provide your users with a back button.

Colin Barrett
+3  A: 
[self presentModalViewController:myViewController animated:NO];

Will pop up a new view, no animations, nothing. To get rid of it, inside myViewController:

[self dismissModalViewControllerAnimated:NO];

Though I reccomend you use the nice sliding animations (change NO to YES.) And yes, you can stack them up. I think this is better than creating a new UIView, but I may be wrong.

Isaac Waller
A: 

Why don't coders just use html embedded in their apps.. It is way easier than C and cocoa. Obviously it's easier for me... I'm 12 and have coded in HTML JavaScript, and CSS, and a bit of PHP, and i know how to make a simple iPhone app (webview one).

I don't understand. Why go to all the trouble? It makes no sense to me :S

Please reply. Thanks

-Sam

Well, if you're doing anything high-performance, if you need to play iPod music during the app, if you want to use OpenGL, if you want your app to look and feel like an iPhone app, if you want to use Core Data, if you want to consume Bonjour services, or if you want to do anything more than displaying simple data, you might use Objective-C, C, C++, etc.
Jeff Kelley
Rendering a web view is not a native app; it does not give the same feel and experience.
Ariejan