As in the screenshot 1, I am trying to design view that is longer then screen size of iPhone.
and in second screenshot I changed the size to freeform which is giving me liberty to create longer view than iPhone's length.
My question is is it a standard way to solve this problem. where as my understanding was that we are not suppose to use xib files anymore after storyboard because every thing was moved to storyboard.
So to solve this this problem Do I have to use view(xib) and make it as subview of UIscroll view.
is that a standard way to solve these kind of problems or do we have something with storyboard equivalent which is more efficient ?
PS: I have been researching this problem from past few days. All related questions over here and web, are adding UIView programmatically to ViewController but not a single example I found where one is designing the UIView in Xcode thru xib file and adding it to UIScroll View. Which is common real world problem. all the app where views are longer or wider than screen size are not done programmatically all together. At least I think they are being designed and them added to the Viewcontroller. Please correct me If I am wrong.
The answer is, as it's always been on iPhone, modal views which come and go as needed. You can temporarily add child view controllers, alert views, 3rd party iphone compatible popover knockoffs....
Of course UIView still exists - so where is the problem? What you probably mean is that you cannot set an UIView in a storyboard, storyboards only contain view controllers. But you can still make a xib file containing an UIView of any size you like, and add that one to your scroll view.
Related
I am working on a swift project in Xcode right now and one of my view controllers is a UITableViewController. I used swift to alter the size of the table view in the controller so that it does not fill up the entire screen. However, I want to set a background image for the entire view controller which I am unable to do since XCode is not letting me add an image view between the table view controller and the table view. Is there any way to do it using swift? Thank you.
I think I can help out.
If you're using Apple's UITableViewController - does that mean you altered the tableView's height in the storyboard? I think a better solution is to just use a regular UIViewController, add a tableView with whatever height you want it inside a UIViewController's view.
Often times I would recommend steering away from using Apple's custom things because you lose flexibility. Just make your own custom thing instead!
UIViewController > View > TableView & UIImageView
Make sure your tableview has a clear background!
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.
I want to load in an UISplitView an iPhone XIB, but it should be resized to full screen of the iPad... How can i do it? I dont want to convert the XIB itself!
I have read all the other solutions, but I do not want a second XIB, I just want to show it on both devices iPhone and iPad in its specific size.
So if I load it on the iPad by using the UISplitView, it should be in the full size, and if I load it on the iPhone, it should only have the iPhone size.
First off, there's no such thing as a UISplitView.
From the documentation:
The UISplitViewController class is a container view controller that manages the presentation of two side-by-side view controllers. You use this class to implement a master-detail interface, in which the left-side view controller presents a list of items and the right-side presents details of the selected item. Split view controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.
So UISplitViewController is just a container. You just pass a master view controller and a detail view controller to it. The master view will be displayed in a popover controller in portrait orientation.
I think either I misunderstood you or your approach is wrong. The reason why this class is not supported on the iPhone is because it wouldn't make any sense. You can't just "resize the splitview" or whatever, you have to redesign your interface separately for the phone. It's difficult to give you any concrete suggestion without knowing what you're doing. Figure out what are you trying to achieve, have a design, make separate nibs for each device and try to reuse code and views as much as possible.
Matt Gemmell wrote a SplitViewController that you can use as subview for the iPad (http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad/). You can check the source if you could use this for iPhone too. I found the source too heavy, I simply created an UITableView that loads other views when selecting a row (sort of a fake splitview).
I have seen this question posted several times with no useful answers. I am trying to place a toolbar above my UIKeyboard in my iPhone app, but am having difficulty. I found this example which works GREAT, except that my view is a UITableView instead of the standard [self.view addsubview:...]. Can anyone figure out how to apply this to a UITableView?
In short, I have several UITextFields in my table cells, so I want the toolbar to appear above the keyboard for those cells.
Many thanks,
Brett
Just don't use the table view directly as a view.
Use a view that will have a table view inside it.
This way you will be able to use the tutorial as is...
In my opinion this way is much better - I don't have view controller with a single table view in any of my applications. There is always something additional on the screen...
In addition, I don't think that using parentViewController is good solution.
Not always you have one.
Actually, I don't even understand how it works for you...
A work around for this would be to create a hidden textfield in a viewcontroller and present it modally with it begin the first responder. The view can be completely transparent and the toolbar can be configured using the interface builder.
I have been spending time learning how to use the iPhone SDK. I've read "Beginning iPhone Development: Exploring the iPhone SDK" from cover to cover and I've never seen an example of multiple views within one XIB.
To illustrate what I mean, here is a screen shot of a XIB with the simple configuration of what I'm referring to:
alt text http://theopensourceu.com/wp-content/uploads/2009/04/one-xib-multiple-views.png
I figure that there has to be a very specific reason that I've never seen this. In Apple's examples and in all of my readings thus far, multiple XIBs are used with only a single 'view' (and sometimes the Navigation Controller or a Tab Bar Controller, etc). What is the reason for this? Should I avoid multiple views inside a XIB? What are the advantages or disadvantages to to either method?
Thank you in advance
It's a question of memory optimization and loading times. If you put all your views in one XIB, then when your application launches, it has to load the entire XIB into memory and construct all of the objects for all of the controls, and this takes a non-trivial amount of time.
If instead you separate your views into separate XIBs, then your app will start up much faster, because only the XIB containing the initial view will be loaded, and it will also use less memory at first. Then, when the view changes, you can load the XIB containing the new view lazily. This will incur a minor hitch when opening a view for the first time. If you're really trying to optimize memory use, you can also unload the previous view when switching views, but I wouldn't recommend this, as this will incur a hitch every time you switch views, instead of just the first time you switch to any given view.
Following up on the previous answer, there are some times when you would like to load multiple views at the same time. Here's an example: You are displaying a report with multiple pages and you're going to use a UIScrollView to manage them. When the user is done browsing the report, he will close the report which will dismiss the view.
Create a UIScrollView in a XIB along with a UIView for each page you need. Since the UIViews are part of the XIB, they will be loaded into memory together, all at once, when the report is opened. Create two UIViewControllers and use them to display the page being viewed and the one being scrolled to. As the user moves through the pages, re-use the UIViewController on the page being scrolled away from to hold the page being scrolled to.
This will ensure great performance while the user is flipping through the pages. It loads all the pages at once up front into memory. I only uses two UIViewControllers, and it just changes which views are in them and moves them around.
This also has the great benefit of having all of the pages in one XIB. It makes it easier to edit, and quicker to load than separate XIB's. You just have to make sure you have the memory to load all the pages at once. If it's static content (such as in my case) it's a great way to go.
If you're looking for a good example of how to do this, I found this resource to be an excellent starting point:
http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html
This is a warning to anyone trying to implement landscape and portrait with two views in a single XIB (iOS 4 with Xcode 4). The primary disadvantage of having two views in a single XIB–for me–was that you can only connect a single UIOutlet object in a XIB to a single UIOutlet object in a view controller.
So, for example, if you have a XIB with a view for landscape and a view for portrait, and both views contain the same interface objects in different positions (such as a UILabel in landscape and a UILabel in portrait). It is not possible to link the UILabel in your portrait view and the UILabel object in the landscape view to a single UILabel object in the view controller at the same time.
I find this a disappointment, as the iOS UIViewController documentation (iOS 4.3) suggested that I could implement custom landscape and portrait views by switching between two views programmatically as the screen rotates.
After spending quite some time to figure out how to do this, I discovered that it is possible to have two different views attached to a single view controller, but you need to have outlets for both views. For example, in my view controller, I have two UILabel objects (one to connect to a UILabel in the portrait view; one to connect to a UILabel in the landscape view). In my code, every time I update the landscape outlet, I also update the portrait landscape.
Not very elegant, but it works, and as this is for a simple view with one screen, it won't use up too much memory to have have all the UI objects duplicated in the controller and views. I wouldn't create a project that did it that way again, but it was a good enough work-around for that project.
One reason I place multiple views in one xib is because unlike storyboard xibs don't allow placing header and footer in the table view itself. So I create to separate view for header and footer view and assign them in viewDidLoad.