How to represent view/edit modes with storyboards? - ios

I have an app written in objective c which I am rewriting in swift and cleaning up/modernising at the same time. The app allows recipes to be viewed and edited. As you can see from this section of the storyboard, it currently duplicates the view layout between view mode and edit mode:
Is there a way I can use a single view in the storyboard to represent the read only view mode and the edit mode?

I have done something like this by putting labels and textFields in the same place in storyboard, and set the textFields to be hidden by default. Then you can toggle the labels and textFields' hidden property (or animate them by changing the alpha property) when the user hits the edit/save button. Your storyboard will look crazy, but nobody will ever see the overlapping labels/textFields when the app is actually running. You'll just have to make sure you're always updating the label text to the newly updated textField text as the user is toggling back and forth.

Related

How to make voice over reads only visible tableview cells

I implemented the voiceover for my app ,in message detail screen when i play the voiceover for whole screen it starts reading the cells which are not visible in the cell, i want to read only visible cells like iPhone default message app.
Assuming you are setting the isHidden flag on your views and that is not preventing them from being read via VoiceOver, you might try setting isAccessibilityElement=false for the hidden items, or using accessibilityElementsHidden.
(I haven't used accessibilityElementsHidden before, but based on the description it sounds like it turns off accessibility (VoiceOver) for the subviews of a vieww.)

UI elements not displaying where they actually are on storyboard in xcode

though the elements show, they don't show in the proper location
When I put UI elements in to the storyboard on this app that I'm working on they do not show up in the right location. I can edit them, move them, manipulate them... but all of it shows up lower than where they are actually located. then on this second viewcontroller that I have created, the header from the first viewcontroller is now showing up over there.
Not really sure if there is a way that I can reset the storyboards or get this to clean up at all.
thanks.
delete all your constraints first from the left hand side of the story board.
run the app and see how it looks
now, set contraints for each widget one by one properly and give it a try
The two buttons were in a stack view with constraints that were throwing them off. Once I removed the stack view and laid out the buttons without the extra view they worked perfectly.

How to completely reset a UITableViewController while still on screen

In my app, I have a very custom UITableView. The cells are all statically defined in Interface Builder, but based on the data structure the table morphs in many various ways. For example, if some data doesn't exist, some cells (or entire sections) are not displayed, custom separator lines are added to account for missing cells, extra views are loaded into the cells, VoiceOver labels change, etc. Because all the cells are static, I set up the table layout in viewDidLoad because I always have the data available at that time. I have always presented this view controller modally, which has worked great. If the user wants to display different data in this table they have to dismiss the view controller and pick a different item to present it again, and it gets rendered appropriately in all cases.
But now I am converting this into a split view controller for iPad, so this UITableViewController never disappears off screen, but I need to set up the table again when the user taps an item. The problem is, because the table is never deallocated, its previous layout still exists when I load more data into it. It would be a lot of work (and an excellent opportunity for many difficult to reproduce bugs to pop up) to test all possible scenarios and try to reset it back to its "pre viewDidLoad state" or undo those previous layout changes if not relevant anymore, if not impossible because I don't have references to the many different custom separator lines generated.
My question is, is it possible to completely reset the table view controller every time a row is selected in the master view controller, therefore allowing it to properly set up the layout because it is not stuck with the previous layout?
I essentially need some way to completely wipe it clean as if it never did any setup, then instantiate it again to cause viewDidLoad get called (or I can move that code to its own method or viewWillAppear). I'm basically looking for a way to reset the tableView back to how it is defined in Interface Builder.
I believe this would result in a flash because the table would completely disappear then reappear in a different format, but that would be acceptable. If that can be animated that'd be nice. If this is really not recommended at all, how do you suggest I proceed to ensure the layout is always appropriate for the data it is presenting?
I was over-thinking this. There's really no need to completely throw away the table and generate a new one. It turned out to be simpler than I had thought to reset the table back to its default state. Just had to be sure to catch every possible thing that could change, including VoiceOver labels, and reset to nil or the default value. Then it can run through the reset code then the layout code every time the data changes and render an appropriate layout. The most difficult part was to remove the custom separator lines, which I solved by adding each one to an array when it's created, then index through it and remove each one from its superview then remove the Autolayout constraints associated with it. One can wrap all of this into a UIView animation block to get a nice fading effect. It's working quite well.

How to use the UIPickerView on the iPad?

Using the UIPickerView on the iPhone is quite simple as it has the right size on the screen, however on the iPad it looks rather strange. I'm wondering how to display it in the best/most user-friendly way possible?
The purpose of the view is to display and edit meta data for an item. I won't need the full screen for it. The picker is used to determine the language the text is written in and is populated from a plist.
As I see it, there are four possibilities:
A full-screen view loaded by the parent view with the UIPickerView directly in it (looks weird)
A modal view which is slightly smaller to put over the parent view and a button to load the UIPickerView separately.
A UIPopoverController which has the same size as the UIPickerView, this will however cause problems with the amount of fields I need on the screen.
Same as 3 but with a button, as in the Calendar.app, which would save some space.
Did I miss something? What would you suggest?
What about a popover controller with your fields, wrapped into UINavigationController, and one of those fields navigates to another screen with just the UIPickerView? Kind of like the alarms are edited on the iPhone.
Also maybe UIPickerView is not the right tool to choose a language. What about just navigating to a list of languages with checkmark selection, not to a screen with a picker?

Changing background in iOS

Hey, I have a UIImageView in my app. And I I have 4 backgrounds created for the app. I want the user to be able to change between these 4 backgrounds. I found a video on youtube to give you an idea of where I'm going.
http://www.youtube.com/watch?v=WO9NRIHU6oQ
The user clicks on a button which open a new view allowing the user to scroll thru the backgrounds and when the user got finds the backround he or she wants the user taps on a button again to use it.
Any Ideas of how I would do this?
Seems like it could be done with a parent view controller containing a button and an imageview. The button causes a secondary view to animate up. The secondary view then has theoretically any number of imageviews (but maybe just three, a previous, a current and a next which are dynamically refreshed from an array of images). Then you just have to sync the current imageview contents with the contents of the imageview in the first view in your parent view controller.
I realize a pile of text like this is probably hard to follow, especially if you're new to iPhone programming, but do some reading into uiview and viewcontroller hierarchies and you should be able to figure something out.

Resources