PDA

View Full Version : UIViewController




shilpa
Jun 8, 2008, 07:08 AM
Hi all,

im having a UIView file which responds to touches and there is also UIViewController. I saw in some example that UIViewController is initallised to UIView using initWithNibName. But initWithNibName is giving warning because it is avialable only for NSViewController.So now how to initalise UIViewController with UIView.

MetronomeViewController *viewController = [[MetronomeViewController alloc] initWithNibName:@"MetronomeView" bundle:nil];

MetronomeView is UIView type file.



white89gt
Jun 8, 2008, 05:08 PM
First of all, in the line of code that you posted, "MetronomeView" isn't referring to a UIView of any kind. That's the name of the Nib file where the interface elements for the metronome interface are.

Secondly, to do what you're trying to do, you have to link the UIView that you're wanting displayed to the View outlet of the UIViewController that you load with the init withNibName: bundle: method.

I hope that made sense. If not, I'll try to explain it better.

shilpa
Jun 9, 2008, 12:53 AM
Hi Thanks for reply,

To link UIView to the View outlet of UIViewController that i load with the init withNibName: bundle method is giving me warning.
so how to resolve that warning.In debug mode UIView of metronome is not geting loaded.

shilpa
Jun 9, 2008, 12:55 AM
Hi Thanks for reply,

To link UIView to the View outlet of UIViewController that i load with the init withNibName: bundle method is giving me warning.Warning is MetronomeViewController does not respond to init withNibName: bundle method. This method is used for NSViewController.
so how to resolve that warning.In debug mode UIView of metronome is not geting loaded.

tacoman667
Jun 9, 2008, 06:54 AM
Have you tried "bundle:[NSBundle mainBundle]"?

white89gt
Jun 9, 2008, 09:08 AM
After posting my reply to the OP, I decided that I should try to figure out how to do it as well. I made a simple app that has two XIB files. The first, MainWindow.xib, holds a navigation controller and the first interface screen. The second XIB, which I created as a view XIB only, holds the second screen and a navigation bar. When you click on the button on the first screen, the second screen loads and slides in from the right. Then when you hit the back button on the nav bar, the original view slides back in from the left. When I get home this afternoon I'll zip up the directory contents so you can see what I've done. There's very little code, most of the linking is done in IB.

shilpa
Jun 10, 2008, 04:39 AM
Thank you for your reply.
All these days i was working on iPhone sdk beta version 3.0,yestarday only i have installed 6.0.I think it will work fine but still i will be waiting for ur zip file of working sample code.

Coma2nd
Jun 20, 2008, 05:24 AM
Hi all,

it's a bit emberassing ... but i've got some kind of exactly the same problem :(

I'm quite new to Cocoa ... so if you wouldn't mind and you still have the example somewhere zipped ... it would be very welcome :)

Thanks in advance^^

white89gt
Jun 20, 2008, 08:37 PM
Here's the controller demo I promised a while ago. It uses a navigation controller, but the same techniques can be used with UIViewController.

Dowload (http://www.austinbull.com/controller.zip)

Coma2nd
Jun 22, 2008, 05:55 AM
Here's the controller demo I promised a while ago. It uses a navigation controller, but the same techniques can be used with UIViewController.

Dowload (http://www.austinbull.com/controller.zip)

Great. Thanks for your help^^

markgamber
Jul 31, 2008, 08:05 PM
After two days of getting my backside kicked by an app, I stumbled across this thread and the linked download helped. The app works! So another big THANKS from me, also!

MikieMikie
Jun 30, 2009, 03:34 PM
Here's the controller demo I promised a while ago. It uses a navigation controller, but the same techniques can be used with UIViewController.

Dowload (http://www.austinbull.com/controller.zip)

Me, too. I can't thank you enough for this. Everything started working for me. :D

Chetmun
Aug 13, 2009, 10:57 AM
I'm missing something. I'm trying to bring in a new view after pressing a button on the first one. Apparently the following code only works in certain situations:

SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];

I use this code in another app and it works just fine. So it's something in the way things are set up I guess. The other app was nav-based but this one is just two views. I probably need to specify something somewhere or make some link in IB or something. (I have already verified the button fires the above code so that link is fine.)

Anyone have any ideas what I could be overlooking?

dejo
Aug 13, 2009, 11:03 AM
The other app was nav-based but this one is just two views.
If your app is just two views, you probably don't have a navigationController and thus pushViewController isn't going to work (it's a UINavigationController instance method).

Chetmun
Aug 13, 2009, 12:24 PM
If your app is just two views, you probably don't have a navigationController and thus pushViewController isn't going to work (it's a UINavigationController instance method).

I was thinking about that. So what's the way to just pull in another view? I have the controller (.h and .m) and a nib for the other view. How do I bring it in from a button on the first view?

dejo
Aug 13, 2009, 12:40 PM
So what's the way to just pull in another view?
I assume by "pull in" you would prefer some sort of animation then, yeah? There are a number of ways to achieve something along these lines. The simplest would be to use UIViewController's presentModalViewController:animated: instance method. This should slide in the new view from the bottom, the default. Or, you can take advantage of the UIViewController's modalTransitionStyle property to flip in the new view or do a cross dissolve. And, if you want to get even more fancy, you can use an animation block to add lots of different kinds of effects to a transition.

Chetmun
Aug 13, 2009, 12:46 PM
I assume by "pull in" you would prefer some sort of animation then, yeah? There are a number of ways to achieve something along these lines. The simplest would be to use UIViewController's presentModalViewController:animated: instance method. This should slide in the new view from the bottom, the default. Or, you can take advantage of the UIViewController's modalTransitionStyle property to flip in the new view or do a cross dissolve. And, if you want to get even more fancy, you can use an animation block to add lots of different kinds of effects to a transition.

Great, sounds like a good thing to try. So I have a line of code like this:


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

I put in the "presentModalViewController". But what about the "self navigationController"?

dejo
Aug 13, 2009, 01:02 PM
But what about the "self navigationController"?
Replace that with a reference to your UIViewController instance.

Chetmun
Aug 13, 2009, 01:14 PM
Replace that with a reference to your UIViewController instance.

OK. I have two UIViewControllers: the one I'm looking at (which is where the code is that we're talking about) and the one I'm trying to get to (SecondViewController).

Is this a "[self something]"? I have created an instance of the second view controller called "controller" as you can see...


SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[[what goes here] presentModalViewController:controller animated:YES];

dejo
Aug 13, 2009, 01:25 PM
Is this a "[self something]"
Even shorter. What is "self"?

Chetmun
Aug 13, 2009, 01:31 PM
Even shorter. What is "self"?

Well, this was my original code which worked in another app.

SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];

Chetmun
Aug 13, 2009, 01:49 PM
Well, this was my original code which worked in another app.

SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];

Thanks for your help, dejo! I still have a problem but your advice paid off. The line that eventually worked (though I didn't know it was working!) was:

[self pushViewController:controller animated:YES];

Since I was going to a view with a table (and not handling that properly), the app was still crashing. So I'll work on that, now. Thanks!!

dejo
Aug 13, 2009, 01:51 PM
Ignore. Answer found.