Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

shilpa

macrumors member
Original poster
May 29, 2008
33
0
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:mad:"MetronomeView" bundle:nil];

MetronomeView is UIView type file.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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^^
 
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
 
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!
 
New View

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:mad:"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?
 
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?
 
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.
 
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"?
 
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...

Code:
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[[[B]what goes here[/B]] presentModalViewController:controller animated:YES];
 
Even shorter. What is "self"?

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

Code:
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
 
Well, this was my original code which worked in another app.

Code:
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:

Code:
[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!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.