I am a newbie summoned with lot of Questions. I am working with UITabBarController Window base application. Is it necessary to Delegate UITabBarController to AppDelegate. Its working fine for me with both delegating and not delegating.
i got some idea of delegate while working with UITableViewController. Please let me know what will happen with and without delgating UITabBarController.
Please suggest any Material or PDF or Book where i can get good idea with AppDelegate other than Apple docs.
You should read about the Model-View-Controller (MVC) paradigm and how delegates fit into it. A good source would be Apple's document on the matter, as well as most beginning iPhone Development Books. I would suggest this one, and a good starting place for MVC is here.
To answer your specific question, you want your AppDelegate to implement the UITabBarControllerDelegate protocol " when you want to augment the behavior of a tab bar. In particular, you can use it to determine whether specific tabs should be selected, to perform actions after a tab is selected, or to perform actions before or after the user customizes the order of the tabs. After implementing these methods in your custom object, you should then assign that object to the delegate property of the corresponding UITabBarController object." (From Apple's Class Document here.
In simplified terms, you use it when you want to do something custom/specific when a viewController is selected from the tab bar (– tabBarController:didSelectViewController:)or will be (– tabBarController:shouldSelectViewController:). It can also be used to help with customizing the viewControllers showing on the tab bar if you have a need for more than allowed to be displayed at once (using a "More..." or whatever tab).
Related
I am new to iOS development. I could see Apple's guide about Modality.
However, I don't know how to implement a custom modal dialog that looks similar to how Gmail app's:
How should I get started? Are there sample codes anywhere for self-learners to follow along?
Thanks a lot
You should investigate UIViewControllerTransitioningDelegate examples.
This will allow you to define a custom transition that you could reuse across a number of different view controllers. It also allows you to decouple transition logic from where the modal is being presented or what is being presented.
I'm creating an app that implements a Facebook and a Twitter service. In my view I have a button that toggles sharing on Facebook/Twitter or not. If Facebook/Twitter aren't connected, then the button will show "connect to".
When I click the button, a method in my controller (not my viewcontroller) will try to toggle the value because this controller tracks the state of my app. When I'm not connected to a social network my controller will notice and will call the correct service. This service will start a webview to provide the user credentials.
And now my question:
When I'm in my service and I need to provide credentials via a webview. When I want to show this webview I need to pass a View Controller that will handle the presenting. How do I provide a viewcontroller here?
Approaches I found:
Call the appdelegate singleton and get the current presenting
viewcontroller (I find this dirty but correct me if I'm wrong).
Since I'm injecting my service into my controller in
appdelegate.didFinishLaunchingWithOptions I could inject the UIWindow
of the appdelegate and ask for the current presenting viewcontroller
(Is almost the same as the first approach)
Create a protocol implemented by a viewcontroller. The service has a property that is equal to that protocol and in my app delegate inject the
viewcontroller into the service.
Have a property in your controller
that will be the presentingviewcontroller and let your controller
implement the approach #3 protocol. When a function of that protocol
is fired, the controller will handle it and use the
presentingviewcontroller property for the webview. I only need to
inject a viewcontroller into my controller in the appdelegate.
Don't implement anything view related in that service.
My current implementation is approach #3.
If some things are not clear, please let me know.
Any help is appreciated!
Thanks in advance!
I was hoping this question would of got more attention, I was interested to know how other people would handle this situation.
As you have already stated, there are a few ways to achieve what you need, but the answer depends on having knowledge of the application.
I would definitely try to keep business logic and UI as separate as possible, there are two methods that I can think of to do this, but they are pretty much the same thing.
Make the (non UI) controller responsible for the login check with a callback function, you can then leave the controller responsible for business logic and the calling ViewController responsible for rendering any UI as a result of that check.
As you suggested, using protocols, your controller could have a delegate that will be a ViewController that conforms to your protocol. Then usage would just be getting your shared instance, setting the delegate and calling the required fuctionality.
I would likely favor option 2 to be more Swift-like as it is a protocol orientated language.
If the controller is acting globally and accessed from anywhere within the application you could potentially end up duplicating a lot of code to make these checks, you could get around this by creating an extension of UIViewController which provides the functionality to interact with the controller.
I hope this helps, Would definitely be interesting to see the way other people would approach this.
I'm new to Swift, so I apologize for my lack of knowledge of almost anything related to Swift.
Right now, I'm developing an app that uses the ARSlidingPanel library, so now there are two ViewControllers present on the screen (Main view, with the dark background, and Panel view, which is the green background). I want to be able to set vars/call functions from the Panel view to the Main view. For example if I click a button in the panel view, I want to display some text in the main view. Right now I've started with using static vars but from my knowledge of Java/Android, I know this is probably not the right way to go. Any tips for a cleaner/more acceptable way of doing things?
There are a few different options here. However, the first thing that comes up to mind is if you really need to use two independent view controllers for the same view?.
One solution would be to use delegates. Write a swift protocol that has has the methods and functionality you want to expose, for example setting up values in the view controller's outlets, then implement the protocol in one view controller. In your other view controller, you can then create a delegate variable of type UIViewController -let delegate: UIViewController - and use that instance of your delegate to modify the view. Here's a guide on this
Even better, you can add view controllers as sub view controllers
of your view, apple provides a good bit of documentation on this, you
can find it
here.
Hope this helps.
I have a UIViewController having two parts:
a UIView
a bar having multiple drop down menus arranged horizontally and having thumbnail images at the top
Because second part is little complex I've decided it to be a UIViewController but now I have some concerns:
Because I have drop down menu, menu will exceeds the bounds of the bar. How can I handle it?
Is it a good way to have a UIViewController inside a UIViewController?
How can I implement a drop down menu? As far I know IOS doesn't have drop down menus.
To use a controller within another controller, you employ a custom container view controller.
See Creating Custom Container View Controllers section of the View Controller Programming Guide for iOS.
Also see the appropriate Implementing a Container Controller section of the UIViewController Class Reference.
Also refer to the WWDC 2011 video, Implementing UIViewController Containment
In iOS 6, you can set up storyboards with container views that automatically employ embed segues, saving you from needing to explicitly call addChildViewController and the like, if you're using storyboards. Check out the "container view" object in Interface Builder. If you're going to be changing the child controller, you'll have to employ the API referred to in the above links, but for the configuration of the first child, you can set that up in Interface Builder in iOS 6.
In this case, setting up a controller containment could be the right way. The only limitation is that it works for iOS 5 and greater.
Here, what you have to do:
// add as child VC
[self addChildViewController:_barViewController];
// add it to container view, calls willMoveToParentViewController for us
[_containerView addSubview:_barViewController.view];
// notify it that move is done
[_barViewController didMoveToParentViewController:self];
Here, you can find additional info Containing ViewControllers. Obviosly Apple doc is your friend. In addition, if you search for "uiviewcontroller containment" you can find a lot of tuts out there.
If your app needs to target devices where iOS 5 is not the minimum, you should rely on a UIViewController and two different views.
About drop down menus, in my opinion they don't work so well with touch interfaces. There are some alternatives, for example an instance of the UISegmentedControl class. Here you can read Apple UI design guidelines about segmented controls: http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW1. If you explain a little bit more about your desired UI functionality we could offer you a better alternative from the user experience point of view.
If you insist with drop down menus, there are some third party control libraries available out there; for example: http://www.cocoacontrols.com/
I'm at a point in the development of the app I'm working on where in order to complete the assignments given to me, it seems like the best way to accomplish what I need is to combine a UINavigationController with a UITabBarController.
Structurally, the app has a home page, and the rest of the app is navigated through the UITabBarController. This is a sound design for the original, but when I took over the development process of this, I had to make a lot of additions to the app, and there's technically supposed to be a "second" section which adds extra "features" if you will that aren't necessarily related to the main functionality of the app itself.
Basically, since everything begins at the Overview, the user is supposed to have a choice between just diving into the app itself, or using some of these extra features. I'm thinking the Navigation Controller would be fitting for the extra features, but I'm not sure how I can add to it.
What I need to know is - is this solution to the problem sound? If so, what's a good way to accomplish this? Is it ok to have a separate UIWindow class to link the Navigation Controller up with the TabBar Controller?
Granted, this app has used a lot of nib files, and every time I've tried to do something programmatically, it just hasn't worked. Thus, if someone could point out a NIB method of achieving this, I'd appreciate it.
According to Apple recommendation, UITabBarController should always be the root view controller of your app. So basically your main view is just one tab of your tab view controller, and so you just need to embed your main view controller in a navigation controller. This way you can navigate to whatever page you wish within that tab using the navigation controller, or you can go to other tabs using the tabbar controller.