-1

Some existential doubt, I have been researching on various sites and I have several examples, but I have 2 questions that I couldn`t clarify:

Navigation Controller: I have seen about 10 examples of Navigation Controller but I cant understand it, I see as the delegates declare and show the home screen that will contain, as well, as included in the XIB files.

However, this is not the case that I need, and I already have my principal screen (Window) to load (in this case my login window)

I hope that what I call a screen from the main screen contains the navigation controller and go from there, moving several screens with navigation controller. But ... as I do that the screen contains the navigation controller if he declares it is already busy for my login? and do not want my application has navigation controller, but only certain specific screens (because of them depend on some options).

Where I have to declare all without affecting my screen? ahhhh I miss a lot and do not understand this control (UINavigationController). Is to serve, but not consume it on the screens as I desire, and not in the entire application.

What are the delegates?: I have used very little, and as often as I used it because I saw reference to other examples and usually try not to use it because do not know how to use it.

Not if I could explain non-technical manner but a little more understandable that it is all the Delegates. What is it?

How to use?

Do I know where to use it?

I know when I should use it.

It uses little or a lot in quality applications.**

Sorry for the inconvenience, this is because it confuses me because NavigationController and there I left several questions, if I turn to you is because I ran out and for more resources to investigate and analize examples but i can't understand yet.

Manu
  • 50
  • 1
  • 9
  • This rambles on a bit, but I suspect Totumus has the right idea - [read up on delegates](http://stackoverflow.com/questions/1045803/how-does-a-delegate-work-in-objective-c) and the rest will fall into place. – Shog9 Nov 28 '11 at 16:16

2 Answers2

1

On the navigationController matter you should read up on in the appleDocs, they explain it the best way possible and show you which methods to use while working with them. (ref: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html)

Delegates are just a manner of message passing from one object to the next. This also has been written before in this question: How does a delegate work in objective-C?

Basically, delegation is a way of allowing objects to interact with each other without creating strong interdependencies between them, since this makes the design of your application less flexible. Instead of objects controlling one another, they can have a delegate which they send (or delegate) messages to, and the delegate does whatever they do, in order to respond and act to this message, and then usually return something back to the other object.

Delegation is also a better alternative to subclassing. Instead of you having to create your own custom classes to slightly alter the way that other objects behave, or pass them data, delegation allows objects to send messages to their delegates to do work for them without the overhead of creating subclasses to make minor changes to other objects.

Of course, the main disadvantage of delegation is that the delegate methods available are dependent on what the Apple engineers foresee as being useful and what common implementations they expect people to need, which imposes a restriction on what you can achieve. Although, as Quinn Taylor pointed out, this is specific to the Cocoa frameworks and so doesn't apply in all situations.

If delegation is an option over subclassing, then take it, because it's a much cleaner way to manage your code and interactions between objects.

It's also been written in the apple Docs (ref: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html)

Community
  • 1
  • 1
Totumus Maximus
  • 7,543
  • 6
  • 45
  • 69
1

You can add a navigation controller programmatically.

SomeRootViewController *rootViewController = [[SomeRootViewController alloc] initWithNibName:@"SomeRootViewControllernibName" bundle:nil];
UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController:rootViewController];

After this, you can show the view of the navigation controller (navCont.view). For example,

currentViewController.view = navCont.view

As for delegates, as the meaning implies, delegates take care of some actions on behalf of the original class. For example, if you you can take the UIApplication delegate, the UIApplication defers the decision of whether the application should quit or not to the app delegate. These decisions can be taken on run time depending upon your requirement. Delegates are coded using protocols.

Shanti K
  • 2,873
  • 1
  • 16
  • 31