Hi, all
Here is the updated version of the Contacts app with archiving.
It will now let you save and load multiple contacts.
I am just going to list some of the new things added.
Here are the previous and next buttons on the Load View screen:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
@IBAction func previousPressed(sender: AnyObject) { // PREVIOUS BUTTON if index == 0 { index = inventory.itemArray.count - 1 } else { index-- } println("index: (index)") indexLabel.text = "(index + 1)" loadItem(inventory.itemArray[index]) changePlaceHolderText() } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
@IBAction func nextPressed(sender: AnyObject) { // NEXT BUTTON if index >= inventory.itemArray.count - 1 { index = 0 } else { index++ } println("index: (index)") indexLabel.text = "(index + 1)" loadItem(inventory.itemArray[index]) changePlaceHolderText() } |
Here are the 2 functions to show and hide the bottom controls, depending if we have
data or no:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
func isData() { println("Data loaded") previousButton.hidden = false nextButton.hidden = false indexLabel.hidden = false indexLabelView.hidden = false } func noData() { println("No Data") previousButton.hidden = true nextButton.hidden = true indexLabel.hidden = true indexLabelView.hidden = true imageViewL.image = UIImage(named: "nothing_to_see_here.jpg") } |
You can find the full code on GitHub here: Contacts App with Archiving
Here is a demo if you want to test it:
Here is a short demonstration:
Any questions or suggestions – let me know. Thanks !
Please note that Alpha on the UIImageView after loading the picked image is wrong. You should add a line after picking the image to fix it – something like:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
if let image = info[UIImagePickerControllerOriginalImage] as UIImage? {
// use dictionary to look up image
imageView.image = image }
imageView.alpha = 1.0 // Here change the opacity so you can see the loaded image …
// dismiss
dismissViewControllerAnimated(true, completion: nil)
}