A View and Scroll View inside a view - iphone

I am building a Calendar app. I have Navigation based app template. Navigation controller has segmented control having namely Daily and Weekly segments.
Upon clicking the segments i show the relevant View having status bar, navigation controller and bottom toolbar. This is working fine.
My daily view will have a top view and scrollView. Top view will have previous button, next button and date in label. When i add only scrollView inside my dailyView than it works fine, but upon adding top View it gives crash when i try to scroll the scrollView.
Please suggest is it possible? Else, what could be a better alternative? I even tried adding a second navigation bar (this time using the Interface Builder), button than i am not able to change the date in label.
Please let me know if more clarity is required.

I see you have two questions:
Please suggest is it possible? Else, what could be a better alternative?
So I'll go ahead and answer those questions:
What you're trying to do is possible, so there's no need to look for an alternative.
However, I guess the real question is: "Why is it crashing?" and I certainly would answer that, but without crash logs and(/or) code it's nearly impossible to give you a usable answer.

Related

Making too many transparent views makes complicated in iPhone

Before Starting I want to make sure one thing whether we can make the ViewController transparent (alpha), as far my knowledge it is NO.
I have a ViewController which consists of 8 UIButton objects over it. Whenever I press Button1, Button2 I am loading a ViewController. Since the ViewController cannot be made transparent, I just moved that View to my HomeViewController.xib and I am loading the view using -addSubView:. And I am changing the alpha value to make it as transparent.
But the thing is in Button1 View and Button2 View, in both views I am having table view. When I bring everything to the same HomeViewController class , I am having too much of code in a single class.
Is there any way to do this?? Adding many Views in the same ViewController not a problem, but it increases the code too. Which looks ugly. Please help me out.
If I have confused about my question here I am giving a short description of what I would like to do
Whenever I press a Button in ViewController, I want to load a View/ViewController Transparently.
Before Starting I want to make sure one thing whether we can make the
ViewController transparent (alpha), as far my knowledge it is NO.
You can't adjust a view controllers alpha directly. You can adjust a view controllers view properties alpha, ex: myViewController.view.alpha, and you can do this for any view that you want except for your root view (the bottom of the view stack). Lowering your root views alpha would allow the user to see the springboard through your app.
But the thing is , In Button1 View and Button2 View , in both views I
am having table view. When I bring everything to the same
HomeViewController class , I am having too much of code in a single
class.
Is there any way to do this ?? Adding Many Views in the same
ViewController not a problem, but it increases the code too. Which
looks ugly. Please help me out.
I'm not sure I understand the problem here. As long as you format your code correctly and keep well organized this isn't a problem. I personally have used view controllers in excess of 15k lines of code and never had a problem, and I'm sure there are developers that have used way more.
If I have confused about my question here I am giving a short
description of what I would like to do Whenever I press a Button in
ViewController , I want to load a View/ViewController Transparently.
Continue the way you have been describing. (adding alpha adjusted UIView's as subviews) There is nothing wrong with this approach.

Should I use UIViewController or UIView? Making a custom tab bar/nav controller

I am making an app that has both a bottom bar and a top bar (both are customized) and i want them to stay there the entire length of the app while the middle portion switches between views. But the kicker is at some points in the app, i want to have the top bar and bottom bar slide off the screen and be able to be dragged back on.
What i was thinking was to have one main UIViewController with three UIViews (top bar, middle section, and bottom bar) each running code from their own respective files. Sort of like how a Tab bar works with a nav controller. or do i have that backwards? i dont really know... but any constructive advice helps =)
Im fairly new to xcode and i've been trying to find a way for a few days now, so please dont be too harsh on me. Thanks!
In general, we build one view controller for each 'screenful' of content. So the basic advice for you would be to make the app in a way where each 'section' is it's own view controller. This is especially important to the MVC paradigm, where your business logic should be in the viewControllers, not the views (just display and interaction logic there). If you had just one view controller, it would get convoluted FAST by trying to manage multiple sections.
A good route may be this: Embed the whole hierarchy in a navigation controller, which gives you the top bar. Then make a custom view controller class which knows how to make your bottom bar, and have each section subclass that.
The side effect is that the bottom bar will be uniquely created for each section VC. If that is not desirable for you, you can explore view controller 'containment'. It is basically a technique for building components like the navigation controller, which keep certain elements onscreen for a long time, while exchanging 'content' view controllers for a smaller portion of the screen. It's not the easiest thing to do, and should be considered carefully. However, if you really need to keep the same instance of something on screen while other view controllers come and go, it may be the right way to go. That said, consider the other idea first (each section manages it's own bottom bar). You can accomplish it in a way that promotes code re-use, etc.

Best iPhone app approach for project

I'm building an iPhone app and I'm sort of confused about which approach should I choose for views and controllers.
I would like to have a tabbar at the bottom with three options. I would also like to have a main view displayed when the app shows (along with the tabbar) but I don't want this view to be part of the tabbar options.
So, when the app begins, the tabbar has no option selected but the main view displayed. When a tabbar options is selected, in its top bar it should display a back button to the main view. When the back button is pressed, the main view display again with no tabbar option selected.
Which approach should I choose?
Hope it makes sense.
Thanks.
I understand what you're trying to do, but you shouldn't do that. I don't like that design at all. You should have one navigation controller for each tab.
You should probably read Apple's Human Interface Guidelines as it's possible they would reject your App if they thought such an implementation with a TabBarController was confusing.
As an alternative, you could possibly have the "main view" as you call it accessible with a button in the Navigation bar at the top and then add that to all three tabs. Not necessarily a better design but you probably wouldn't be breaking the guidelines.
A better alternative might be to use a UIToolBar at the bottom instead of the Tab bar which has the three buttons spawning your views modally which can then be dismissed as you suggest.
Remember though, your App's users have built up a knowledge of how App's are generally supposed to navigate, feel and control so you should think carefully before deciding to go against that.
Firstly, I think you should reconsider giving your Main View it's own tab. That way it's a no-brainer for the user to return to that screen. BUT, if you STILL don't like that idea, read on...
The UITabBarController has the unfortunate side effect of not being able to be removed once created (even if you delay it's creation by instantiating it programmatically).
SO...
Option 1: Make your MainView a modalPresentation sub-view, displaying it ON TOP of one of the views in your tab bar (hiding the tabs until you're ready to show them again).
Option 2: Give a subview of your first tab a...
mySubViewController.hidesBottomBarWhenPushed=YES;
This will make the UITabBarController disappear temporarily (just on that view, until you're ready to show the tabs again).
Both options seem kinda messy to me, but they are possible. Depends on how well you execute them, I suppose.
Hope this helps!
You could add the main view as another tab.
OR
You present the main view modally when the app starts over the tab bar views.
The first option would be used more if the view holds the same kind of content as the tabs, for example if the app was an online store, the tabs would be Categories, Search and Recently Added, with what you call the "main view" being the Home page (showing offers or something). (So all the views/tabs would be showing products on the store)
The second option would be more if the content of the main view is different to the tabs.
Keeping with the online store example, if the tabs were Categories, Search and Recently added and what you call the "main view" being a login/logout screen. (so the tabs would be showing products, but the modal view ("main view") being more admin related, and it's main purpose not being to display products.

Multiple UINavigationControllers similar to Maps

I'm looking to create a UI similar to that of the Maps application just to try out some odds and ends and brush up on my knowledge of interface builder.
What i'm struggling to discern at the moment is how the Maps application handles the interactions between the toolbar and the navigation controller and which UI elements are needed to mimic the interface. I'm guessing that the Maps app only has one view controller which kind of negates the need for a navigation controller so i'm not sure if i'm using the right application template currently but i'll come back to that one later.
To give you an idea of what I'm looking to copy, if you search for directions between two locations and then hit route, the navigation controller changes from:
[Clear] Directions [Cancel]
to:
[Edit] {car | train | walk} [Start]
That's all fine so far, nothing out of the ordinary from what i'm used to doing. What is confusing me however is the semi transparent view underneath the navigation controller that displays the total distance and time (or other information depending on the search method). What is the UI element? Is it simply a toolbar tacked on to the main view? How would I go about adding this to my app, is it part of the view, or part of the navigation controller?
Also, in a similar vein... Clicking the "Search" segment in the toolbar displays the search field at the top of the app. Is this in the navigation controller, or is the navigation controller hidden whilst the search field is displayed? Again, clicking "Directions" displays the search field but this time with an additional search field and a button to switch the order of the fields. How is this achieved?
I'm not so good with the terminology so excuse me if i've mixed up some terms. I'm just trying to get to grips with the UI elements as i've spent most of my time learning OpenGL so it's all a bit new to me still. If anyone can point out the right UI elements used in the Maps application, that would be greatly appreciated!
Many thanks for reading.
Edit: I've uploaded an image to illustrate the UI elements i'm querying in this question.
I have no inside information, so I'm speculating on how I'd do it.
I'd use a UIToolBar for both the top and bottom bars, not a navigation bar. You can put a tool bar anywhere as they're just a subclass of UIView.
The semi transparent view underneath the navigation controller is likely just a custom view on top of the map view. Again, just a subclass of UIView.
The items in both toolbars would call methods in the view controller that could change the contents of either tool bar or hide or show other views.
For example, the Search button might call a showSearchToolbar: method, while the Directions calls a showDirectionsToolBar: method. Both methods would just change the contents of the top tool bar and hide or show the view beneath the top tool bar.
Check out the UICatalog example code from Apple to see how to dynamically change the contents of the tool bar.

Modifying code to add a home button

Currently the code I need to modify uses a tabBarController with a single selection inside it which takes the user back to the root view, but because it is a tabBar then the whole of the tab is selectable and I need it so only the button positioned in the middle of the tab bar is selected.
I am fairly new to this but know it is not a tabBar that is needed here but something else, maybe just place a button there. Any help would be fantastic. I would post the code up but I am unsure which section would be required. I hope I made myself clear enough :)
Rowley
Tab bars are for switching among different views. If all you want is a home button, a tab bar would not be a good choice. You could use either a simple UIButton, or possibly a tool bar -- though the tool bar is generally used when there is more than one action the user might take.