From 2c2587303561cb1fc97fcaeb64d4d4b866aeb0f9 Mon Sep 17 00:00:00 2001 From: Jay Stakelon Date: Fri, 31 Jul 2015 13:23:23 -0700 Subject: [PATCH] Add master/detail example project --- JSSAlertViewMasterDetail/.DS_Store | Bin 0 -> 6148 bytes .../project.pbxproj | 444 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../AppDelegate.swift | 63 +++ .../Base.lproj/LaunchScreen.xib | 41 ++ .../Base.lproj/Main.storyboard | 241 ++++++++++ .../DetailViewController.swift | 112 +++++ .../AppIcon.appiconset/Contents.json | 68 +++ .../JSSAlertViewMasterDetail/Info.plist | 57 +++ .../MasterViewController.swift | 75 +++ .../JSSAlertViewMasterDetailTests/Info.plist | 24 + .../JSSAlertViewMasterDetailTests.swift | 36 ++ 12 files changed, 1168 insertions(+) create mode 100644 JSSAlertViewMasterDetail/.DS_Store create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail.xcodeproj/project.pbxproj create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/AppDelegate.swift create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/LaunchScreen.xib create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/Main.storyboard create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/DetailViewController.swift create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Info.plist create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/MasterViewController.swift create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/Info.plist create mode 100644 JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/JSSAlertViewMasterDetailTests.swift diff --git a/JSSAlertViewMasterDetail/.DS_Store b/JSSAlertViewMasterDetail/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..343624c3706bf8d9e8fd95545b3599080fb654ae GIT binary patch literal 6148 zcmeHKK~BR!3>=ppin#R1G2#J8{XwY01&ITS#2J)SP}C?9q=I8E{DH6V44%MG7_XPA zRp3^t3fYxCyN&Z_YmfJ~R=1Q-JtQ56S=G(U(wSMA9ldWJ*^Yb-FsBU)Tz-ivm} zJ~E(ZcY+J#{G4I^{APH@C2sM=^VCz#Xj{(bj5@^&3e+g+Yxu0j!{Tm|7j@OxCf~2N zwQf~sS-ETr;N$c4Ev&wk-&@t?pRC*5ukj%IzjAQ~oB?NG?-*dsRv8@`x^)Je0cT*v zfW99Rs$v?kGYqc|n$Q9e^%@z3<8bF8Ch8!j5j#VAC}OEZOO@DSh^5n?#JDtKXK3k= z*nCL*W{Dlj_l--E5DrNV-8uu#z$OC+HXUpIKmWb|-%RqEGvEyTD+Xkk<=K>5inX=3 vIjyw`^@ggVah>5Rg@aIv8LOrEm>PusL + + + + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/AppDelegate.swift b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/AppDelegate.swift new file mode 100644 index 0000000..5632ebf --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/AppDelegate.swift @@ -0,0 +1,63 @@ +// +// AppDelegate.swift +// JSSAlertViewMasterDetail +// +// Created by Jay Stakelon on 7/31/15. +// Copyright (c) 2015 Jay Stakelon. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate { + + var window: UIWindow? + + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + // Override point for customization after application launch. + let splitViewController = self.window!.rootViewController as! UISplitViewController + let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController + navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem() + splitViewController.delegate = self + return true + } + + func applicationWillResignActive(application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(application: UIApplication) { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + // MARK: - Split view + + func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController:UIViewController!, ontoPrimaryViewController primaryViewController:UIViewController!) -> Bool { + if let secondaryAsNavController = secondaryViewController as? UINavigationController { + if let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController { + if topAsDetailController.detailItem == nil { + // Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded. + return true + } + } + } + return false + } + +} + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/LaunchScreen.xib b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..bc627e7 --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/Main.storyboard b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/Main.storyboard new file mode 100644 index 0000000..5e19351 --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Base.lproj/Main.storyboard @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/DetailViewController.swift b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/DetailViewController.swift new file mode 100644 index 0000000..36667d6 --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/DetailViewController.swift @@ -0,0 +1,112 @@ +// +// DetailViewController.swift +// JSSAlertViewMasterDetail +// +// Created by Jay Stakelon on 7/31/15. +// Copyright (c) 2015 Jay Stakelon. All rights reserved. +// + +import UIKit + +class DetailViewController: UIViewController { + + @IBOutlet weak var detailDescriptionLabel: UILabel! + + + var detailItem: AnyObject? { + didSet { + // Update the view. + self.configureView() + } + } + + func configureView() { + // Update the user interface for the detail item. + if let detail: AnyObject = self.detailItem { + if let label = self.detailDescriptionLabel { + label.text = detail.description + } + } + } + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + self.configureView() + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + @IBAction func basicAlertButtonPress() { + JSSAlertView().show(self, title: "Boring and basic, but with a multi-line title") + } + + @IBAction func standardAlertButtonPress() { + JSSAlertView().show(self, title: "Standard alert", text: "A standard alert with some text looks like this", buttonText: "Yay") + } + + @IBAction func customColorAlertButtonPress() { + var alertview = JSSAlertView().show(self, title: "Custom color", text: "All of the cool kids have purple alerts these days", buttonText: "Whoa", color: UIColorFromHex(0x9b59b6, alpha: 1)) + alertview.setTextTheme(.Light) + } + + @IBAction func customIconAlertButtonPress() { + var customIcon = UIImage(named: "lightbulb") + var alertview = JSSAlertView().show(self, title: "Custom icon", text: "Supply a UIImage as the iconImage for sexy results", buttonText: "Yes", color: UIColorFromHex(0x9b59b6, alpha: 1), iconImage: customIcon) + alertview.setTextTheme(.Light) + } + + @IBAction func customFontsAlertButtonPress() { + var alertview = JSSAlertView().show(self, title: "Check it out", text: "This alert is using a custom font: Clear Sans to be specific") + alertview.setTitleFont("ClearSans-Light") + alertview.setTextFont("ClearSans") + alertview.setButtonFont("ClearSans-Bold") + } + + @IBAction func infoAlertButtonPress() { + JSSAlertView().info(self, title: "Heads up!", text: "This is the built-in .info style", buttonText: "Aight then") + } + + @IBAction func successAlertButtonPress() { + JSSAlertView().success(self, title: "Great success", text: "This is the built-in .success style") + } + + @IBAction func warningAlertButtonPress() { + JSSAlertView().warning(self, title: "Take warning", text: "This is the built-in .warning style") + } + + @IBAction func dangerAlertButtonPress() { + JSSAlertView().danger(self, title: "Oh, shit.", text: "This is the built-in .danger style") + } + + + @IBAction func twoButtonAlertPress() { + var alertview = JSSAlertView().show(self, title: "Standard alert", text: "A standard alert with some text looks like this", buttonText: "Yep", cancelButtonText: "Nope") + alertview.addAction(closeCallback) + alertview.addCancelAction(cancelCallback) + } + + @IBAction func kitchenSinkAlertViewButtonPress() { + var customIcon = UIImage(named: "lightbulb") + var alertview = JSSAlertView().show(self, title: "Kitchen sink", text: "Here's a modal alert with descriptive text, an icon, custom fonts and a custom color", buttonText: "Sweet", color: UIColorFromHex(0xE0107A, alpha: 1), iconImage: customIcon) + alertview.addAction(closeCallback) + alertview.setTitleFont("ClearSans-Bold") + alertview.setTextFont("ClearSans") + alertview.setButtonFont("ClearSans-Light") + alertview.setTextTheme(.Light) + } + + func closeCallback() { + println("Close callback called") + } + + func cancelCallback() { + println("Cancel callback called") + } + + +} + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Images.xcassets/AppIcon.appiconset/Contents.json b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Info.plist b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Info.plist new file mode 100644 index 0000000..efadafb --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/Info.plist @@ -0,0 +1,57 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.stakelon.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarTintParameters + + UINavigationBar + + Style + UIBarStyleDefault + Translucent + + + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/MasterViewController.swift b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/MasterViewController.swift new file mode 100644 index 0000000..4ef0b01 --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetail/MasterViewController.swift @@ -0,0 +1,75 @@ +// +// MasterViewController.swift +// JSSAlertViewMasterDetail +// +// Created by Jay Stakelon on 7/31/15. +// Copyright (c) 2015 Jay Stakelon. All rights reserved. +// + +import UIKit + +class MasterViewController: UITableViewController { + + var detailViewController: DetailViewController? = nil + var objects = [AnyObject]() + + + override func awakeFromNib() { + super.awakeFromNib() + if UIDevice.currentDevice().userInterfaceIdiom == .Pad { + self.clearsSelectionOnViewWillAppear = false + self.preferredContentSize = CGSize(width: 320.0, height: 600.0) + } + } + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. +// self.navigationItem.leftBarButtonItem = self.editButtonItem() + +// let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "insertNewObject:") +// self.navigationItem.rightBarButtonItem = addButton + if let split = self.splitViewController { + let controllers = split.viewControllers + self.detailViewController = controllers[controllers.count-1].topViewController as? DetailViewController + } + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } +// +// func insertNewObject(sender: AnyObject) { +// objects.insert(NSDate(), atIndex: 0) +// let indexPath = NSIndexPath(forRow: 0, inSection: 0) +// self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) +// } + + // MARK: - Segues + + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + if segue.identifier == "showDetail" { + if let indexPath = self.tableView.indexPathForSelectedRow() { +// let object = objects[indexPath.row] as! NSDate + let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController +// controller.detailItem = object + controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem() + controller.navigationItem.leftItemsSupplementBackButton = true + } + } + } + + // MARK: - Table View + + override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + if indexPath.row == 1 { + JSSAlertView().show(self, title: "Standard alert", text: "A standard alert with some text looks like this", buttonText: "Yay") + tableView.deselectRowAtIndexPath(indexPath, animated: true) + } + } + + + +} + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/Info.plist b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/Info.plist new file mode 100644 index 0000000..cab27e1 --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.stakelon.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/JSSAlertViewMasterDetailTests.swift b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/JSSAlertViewMasterDetailTests.swift new file mode 100644 index 0000000..c30cde9 --- /dev/null +++ b/JSSAlertViewMasterDetail/JSSAlertViewMasterDetailTests/JSSAlertViewMasterDetailTests.swift @@ -0,0 +1,36 @@ +// +// JSSAlertViewMasterDetailTests.swift +// JSSAlertViewMasterDetailTests +// +// Created by Jay Stakelon on 7/31/15. +// Copyright (c) 2015 Jay Stakelon. All rights reserved. +// + +import UIKit +import XCTest + +class JSSAlertViewMasterDetailTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + XCTAssert(true, "Pass") + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock() { + // Put the code you want to measure the time of here. + } + } + +}