icon selector using two view - iphone

Need help with the following. I am creating two different combinations of view/controllers that allow me to add/edit a set of information , think tasks or some type of to-do. I have all the data capture/store functionality working.
I decided that it would be nice to have an icon associated to these tasks. So the icon would show up in the UITableview. I commissioned 18 customer 44x44 icons that would be added tot he table.
But there is where I'm stuck:
I was to add/edit views to have the capability to select an icon to attach to the tasks. In order to do so, i added a 44x44 round-rect button with one of the images as a default. I wanted to have that button trigger another view with the 18 icons so the user selects one and it passes control back to the main view and updates de selected icon appropriately.
I created this little 18 icon view together with the main view, which is based on a scroll view. I configured the little icon view to be hidden.
But I have no idea if the little view should be a subview of the main view, who should be the file owner, how do I make it appear hidden as the main view is displayed and toggle t as needed...
I am stumped. Anyone done something like this? Ideas? Things I completely messing up, you can think of?
Thanks in advance

Probably the easiest way to hide and show the view is to adjust the "alpha" property on the view. If you set the alpha of the little view to 0 it will be hidden, and when you set it to 1 it will be showing. So in your awakeFromNib function (or wherever you are doing initialization) you can add the littleView and set the alpha to 0 so it starts hidden. I suggest adding the littleview to your mainview unless for some reason the little view will have any part of it outside of the mainview. Then, when the user selects the icon to change it, you can set the alpha to 1. Finally, when the user chooses from the view, you would set the alpha back to 0.
Note:
This is not the most efficient use of memory because the view is technically always around. So if you think that you will be low on memory I would suggest creating the view programmatically when needed and removing it from mainview when the user is done. (But only do this if you think it will be an uncommon task because creating the view with a bunch of images will probably be a relatively expensive operation).

Related

How to move other uiobjects relatevely when a new view is shown in the main view

I am developing an iPhone app,which contain a page consisting of three UISwitch. When the the UISwitch is in On state the app displays a small view below the switch. This works for all three switches. But the problem is that the small views displayed will overlaps if I switch on two switches at a time. Is there a way to shift all the other view relatevely when those views are displayed..
Thanx in advance....
This sort of problem is exactly what auto layout is good for. When you add a new object, remove and regenerate your constraints (you may only need to change a couple, depending on what it currently in place), then call layoutIfNeeded on the superview. If you do that inside an animation block, it will even animate into the new layout for you.
Its a bit late but this may be what you looking for.
CollapseClick

Best way to show a small view/dialog over an existing screen?

All my views/pages in apps so far have been full screen UIViewControllers that i push and pop from the stack.
I see some apps create a new view/window that appears about the 1/3 the size of the full screen on an iPad, containing tables of items to select or other UI elements. They are commonly used to allow users to filter the current view they were on.
Seeing them in apps, I guess that they are just adding a UIView to there current screen and change its frame depending on where on the screen they want it to appear.
Or am I wrong? Is there another/better way to do this?
I guess you are talking about UIPopovercontroller. There are several tutorials to build the same.check this. Hope that helps you.
It's a little unclear from your question what the view looks like.
If the view is "attached" to a UI element (has a little triangular arrow connecting it to, e.g., a button) and goes away if you tap outside it, then it's a view presented from a UIPopoverController.
If the view overlays everything and dims the content behind it, is likely a model view controller presented with a presentation style of ether page sheet or form sheet.
Both are common and easy to set up. See the class documentation I have linked.
In most cases, these are probably normal modal view controllers whose modalPresentationStyle property is set to either UIModalPresentationPageSheet or UIModalPresentationFormSheet.
Yes you can make your own UIViews and just add them as subviews. Another option for iPads specifically is with the UIPopoverController class.

Design options for iPhone app with numerous (~50) screens, each with the same background

I'm writing an iPhone app (which will be my first ios app) that has about 50 screens, each of which has the same background - where the background is an image covering the entire screen real estate and another image at the top as a banner.
Each screen will have some text along with 0, 1, 2 or 3 buttons appearing beneath the banner image.
What is the best design for putting this together?
The options I could think of were (in every each I was planning on having a root controller which is responsible for displaying each view as appropriate).
1) Have 50 separate screens as xibs (and associated view controllers), each of which contains the two background images plus however many buttons each particular screen needs.
2) Have 4 superclasses as xibs - (representing no buttons, 1 button, 2 button, 3 buttons) and have each of those contain the background images and as many buttons as appropriate. Then have 50 subclasses which simply just set the text and button content as appropriate using the superclasses instance variable outlets.
3) Have the root controller have a view which contains the two background images which is there permanently, and each of the 50 views displays its text and buttons on top of that.
4) (If this is possible, I need to check if a window can have images). Same as 3, except the root controller doesn't have a view, the main window displays the background images and each class displays its text and buttons on the top of this. So each view controller would have to load and display the text and button objects using code (in which case there's not much point to have xibs for them).
Is there another solution? Is one of these the "best" solution?
If I went with 3 would it not be possible to define the position text and buttons in a xib? (because in order to do so they would need a parent view in order to position them in interface builder, but if that were the case then when the view is drawn the background wouldn't be visible).
If 4 is possible, then the root controller has no view, therefore does it still need to be descended from UIViewController, or could it simply be descended from NSObject?
I think at the moment I am leaning towards option 2) as that way I can design all the views visually as xibs, but there are only 4 of them. Unless there is a better more elegant solution.
TIA
What you can do, is one XIB with all the buttons and then you would set then hidden accordingly. Although it would tie you up a bit. The 2) option is more flexible. The 3) is ok too. You could have one rootViewController, just to hold the images and then you could something like this:
[rootViewController.spaceForMyChildView addSubview: myNewViewController.view];
The "spaceForMyChildView" would be a view that would hold your child views.
I would do fusion between 2) and 3) probably.
UIWindow inherits from UIView, so can have anything within it. So (4) is feasible, though you're starting to get into tricky water if you want to support any sort of view rotation.
I'd think an inverted (2) would be the easiest thing — have a single superclass that upon viewDidLoad adds the background and top banner programmatically. Have your specific controllers inherit from that and design them graphically to contain whatever you want, mindful that the image and banner will subsequently be added.
That said, if your views are really as simple as a single text area and up to three buttons, always with fixed positions, then it sounds like a single view that repopulates its fields from a data source, as Jacky Boy suggests, is probably the smartest thing.

Scrolling through UIScrollView in Interface Builder for Xcode 4

This seems to me as though it would be a common problem, but I can't seem to find the answer anywhere. This question seems to address the issue, but I can't seem to get the solution to work and I'm not sure it's referring to Xcode 4.
When using Interface Builder in Xcode 4 and working with a UIScrollView, is there a way to scroll the view down in Interface Builder itself to view/add/edit controls that are out of the viewable section of the screen? I've managed to push a couple controls down using the arrow keys, but now I can't see them and therefore can't manipulate them in Interface Builder. Scrolling the view in IB would be first prize, but if there's a way to even select the controls using a drop-down menu or whatever so I can push them back up with the arrow keys, that would at least be something. Thanks.
Set the ViewController's Simulated Size to Freeform and set a very large height. E.g: 1000 and voilà! You can now scroll to see all the stuff and add even more! :)
P.S: Remember to set set Fixed when you are finish to avoid problems!
Just a workaround which helps in Xcode4:
Expand the Objects Panel which resides on the left of the Interface Builder view (there is the tiny arrow at the bottom of the panel).
Drag your UIScrollView from the view hierachy and place it on the top level.
Now you can resize it to access more content (scrolling to that content did not work for me).
When you are done adding child views to the scrollview, you need to resize it back to be smaller or the same size as the parent view.
After your changes you would need to put back the scroll view where it belongs in your hierachy
I typically do the following when I want to (have to) build a long scrolling screen:
Set the size of the View Controller to Freeform
Set the height of the top level View to something very large
Arrange all the controls that I want on the View
Select all the controls
Select Editor->Embed In->Scroll View
Set the size of the View Controller back to normal (typically Inferred)
Well, there are a few different things you can do. There is a list of items in your view you can open on the left of the workspace by clicking the button that looks like a little play button on the toolbar. Double clicking any item selects it so you can use the arrow keys.
The best option is to use the layout panel (typically on the right) and enter position values manualy. Sometimes I will use this to move my scrollview up to where I can see where I'm working then move it back.
I found a solution although you have to use a Table view controller. If you define the table as static, the scroll works in interface builder when the table is bigger than the windows size. Moreover, a standard view can be added to the top and bottom of the table, these views are scrollable as well. The scroll is made once the controller is selected. I hope you find this trick useful.
I know this isn't exactly what you were looking for, but I always just drag the scroll view out of the view controller onto the "pasteboard" where you can resize it at will and see the whole thing.
Once I make my edits I simply resize it to fit it's allotted space in my view and place it back in the view controller.
set the root view to freeform and ~1000 pt height, go through the child views and set them to this height as well(including scroll view), in the viewdidload method set the height to the appropriate size.

Display a box with contents in Iphone View

I am working on an app which displays user information on the home view. Its a regular tab bar application, which brings up the home view on load. I need to display something like,
Hello Joe,
Your current points are : xxx
I would like this to be in a white curved background box. (The background for the view is blue). Is there something like a UIPanel or something like that. I would really like to avoid having another view or a webView, not sure if thats going to affect the speed of loading the page.
If there were a UIPanel control it would derive from UIView, so I'm not sure why you want to avoid another view. If I'm understanding you, it sounds like you want a custom alert window of some sort. You could just use the UIAlertView control to display your message, but if you are dead set on a custom look, then you will need to use a view.
This shouldn't affect performance noticeably if you are just displaying some text with maybe a button on a custom image. Especially if this is just a tab bar application with nothing too crazy happening in the background (animations, etc.).
I would suggest creating a View either in code (this will be slightly faster, but once again probably not noticeably so) or with Interface Builder that has a black background with an opacity of like .2-.5 and on that view adding a UIImageView set to your custom image (a png of a white curved box with transparent corners). Then put a UILabel with your text and a button to dismiss it.
On load just instantiate the above view and add it to your current view. It will show your message modally. Then capture the button tap event to have it remove itself from it's superview.
There are plenty of examples of how to do exactly this out there and there are even other ways of doing it than what I've suggested. If you need further assistance let me know.