Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 8, 2008, 07:08 AM   #1
shilpa
macrumors member
 
Join Date: May 2008
UIViewController

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.
shilpa is offline   0 Reply With Quote
Old Jun 8, 2008, 05:08 PM   #2
white89gt
macrumors regular
 
Join Date: Jan 2006
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.
white89gt is offline   0 Reply With Quote
Old Jun 9, 2008, 12:53 AM   #3
shilpa
Thread Starter
macrumors member
 
Join Date: May 2008
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 is offline   0 Reply With Quote
Old Jun 9, 2008, 12:55 AM   #4
shilpa
Thread Starter
macrumors member
 
Join Date: May 2008
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.
shilpa is offline   0 Reply With Quote
Old Jun 9, 2008, 06:54 AM   #5
tacoman667
macrumors regular
 
Join Date: Mar 2008
Have you tried "bundle:[NSBundle mainBundle]"?
tacoman667 is offline   0 Reply With Quote
Old Jun 9, 2008, 09:08 AM   #6
white89gt
macrumors regular
 
Join Date: Jan 2006
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.
white89gt is offline   0 Reply With Quote
Old Jun 10, 2008, 04:39 AM   #7
shilpa
Thread Starter
macrumors member
 
Join Date: May 2008
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.
shilpa is offline   0 Reply With Quote
Old Jun 20, 2008, 05:24 AM   #8
Coma2nd
macrumors newbie
 
Join Date: Sep 2007
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^^
Coma2nd is offline   0 Reply With Quote
Old Jun 20, 2008, 08:37 PM   #9
white89gt
macrumors regular
 
Join Date: Jan 2006
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
white89gt is offline   0 Reply With Quote
Old Jun 22, 2008, 05:55 AM   #10
Coma2nd
macrumors newbie
 
Join Date: Sep 2007
Quote:
Originally Posted by white89gt View Post
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
Great. Thanks for your help^^
Coma2nd is offline   0 Reply With Quote
Old Jul 31, 2008, 08:05 PM   #11
markgamber
macrumors 6502
 
Join Date: Jul 2005
Location: Redneck, PA
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!
markgamber is offline   0 Reply With Quote
Old Jun 30, 2009, 03:34 PM   #12
MikieMikie
macrumors 6502a
 
Join Date: Aug 2007
Location: Newton, MA
Quote:
Originally Posted by white89gt View Post
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
Me, too. I can't thank you enough for this. Everything started working for me.
MikieMikie is offline   0 Reply With Quote
Old Aug 13, 2009, 10:57 AM   #13
Chetmun
macrumors newbie
 
Join Date: Aug 2009
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:@"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?
Chetmun is offline   0 Reply With Quote
Old Aug 13, 2009, 11:03 AM   #14
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by Chetmun View Post
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).
__________________
dejo is online now   0 Reply With Quote
Old Aug 13, 2009, 12:24 PM   #15
Chetmun
macrumors newbie
 
Join Date: Aug 2009
Quote:
Originally Posted by dejo View Post
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?
Chetmun is offline   0 Reply With Quote
Old Aug 13, 2009, 12:40 PM   #16
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by Chetmun View Post
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.
__________________
dejo is online now   0 Reply With Quote
Old Aug 13, 2009, 12:46 PM   #17
Chetmun
macrumors newbie
 
Join Date: Aug 2009
Quote:
Originally Posted by dejo View Post
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"?
Chetmun is offline   0 Reply With Quote
Old Aug 13, 2009, 01:02 PM   #18
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by Chetmun View Post
But what about the "self navigationController"?
Replace that with a reference to your UIViewController instance.
__________________
dejo is online now   0 Reply With Quote
Old Aug 13, 2009, 01:14 PM   #19
Chetmun
macrumors newbie
 
Join Date: Aug 2009
Quote:
Originally Posted by dejo View Post
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];
[[what goes here] presentModalViewController:controller animated:YES];
Chetmun is offline   0 Reply With Quote
Old Aug 13, 2009, 01:25 PM   #20
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by Chetmun View Post
Is this a "[self something]"
Even shorter. What is "self"?
__________________
dejo is online now   0 Reply With Quote
Old Aug 13, 2009, 01:31 PM   #21
Chetmun
macrumors newbie
 
Join Date: Aug 2009
Quote:
Originally Posted by dejo View Post
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];
Chetmun is offline   0 Reply With Quote
Old Aug 13, 2009, 01:49 PM   #22
Chetmun
macrumors newbie
 
Join Date: Aug 2009
Quote:
Originally Posted by Chetmun View Post
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!!
Chetmun is offline   0 Reply With Quote
Old Aug 13, 2009, 01:51 PM   #23
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Ignore. Answer found.
__________________
dejo is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
xcode unlocking uiviewcontroller aljuma1995 iPhone/iPad Programming 3 Apr 3, 2013 01:18 PM
How to navigate from UIView to UIViewController fypj2013 iPhone/iPad Programming 6 Mar 25, 2013 04:37 PM

Forum Jump

All times are GMT -5. The time now is 04:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC