From 51b92992b06df32f9d17895a9c3a37c64979b413 Mon Sep 17 00:00:00 2001 From: Miles Crabill Date: Tue, 9 Dec 2014 20:11:42 +0100 Subject: [PATCH 1/4] changes to ui --- socialCalendar.xcodeproj/project.pbxproj | 8 ++ socialCalendar/Base.lproj/Miles.storyboard | 43 ++++---- .../CalendarTabBarViewController.swift | 35 +++++++ .../CalendarTableViewController.swift | 97 +++++++++++++++++++ socialCalendar/Info.plist | 2 +- socialCalendar/LoginViewController.swift | 34 +++++-- 6 files changed, 187 insertions(+), 32 deletions(-) create mode 100644 socialCalendar/CalendarTabBarViewController.swift create mode 100644 socialCalendar/CalendarTableViewController.swift diff --git a/socialCalendar.xcodeproj/project.pbxproj b/socialCalendar.xcodeproj/project.pbxproj index fe528b7..a796cda 100644 --- a/socialCalendar.xcodeproj/project.pbxproj +++ b/socialCalendar.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 024A45BB1A33AB0900757D93 /* CalendarTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024A45BA1A33AB0900757D93 /* CalendarTableViewController.swift */; }; + 024A45BD1A33AB1C00757D93 /* CalendarTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 024A45BC1A33AB1C00757D93 /* CalendarTabBarViewController.swift */; }; 02C91E741A2E08E100B3977B /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02C91E731A2E08E100B3977B /* Accounts.framework */; }; 02C91E761A2E08E500B3977B /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02C91E751A2E08E500B3977B /* AudioToolbox.framework */; }; 02C91E781A2E08ED00B3977B /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02C91E771A2E08EC00B3977B /* CFNetwork.framework */; }; @@ -51,6 +53,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 024A45BA1A33AB0900757D93 /* CalendarTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarTableViewController.swift; sourceTree = ""; }; + 024A45BC1A33AB1C00757D93 /* CalendarTabBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarTabBarViewController.swift; sourceTree = ""; }; 02C91E731A2E08E100B3977B /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; }; 02C91E751A2E08E500B3977B /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 02C91E771A2E08EC00B3977B /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; @@ -169,6 +173,8 @@ children = ( 02F9119A1A2E61EE00B15744 /* Kevin.storyboard */, 02F911971A2E604C00B15744 /* Miles.storyboard */, + 024A45BA1A33AB0900757D93 /* CalendarTableViewController.swift */, + 024A45BC1A33AB1C00757D93 /* CalendarTabBarViewController.swift */, 1079FEF31A2D4AD900654080 /* AppDelegate.swift */, 1079FEF51A2D4AD900654080 /* ViewController.swift */, 02C91E971A2E288700B3977B /* LoginViewController.swift */, @@ -326,10 +332,12 @@ 1079FEF41A2D4AD900654080 /* AppDelegate.swift in Sources */, 103679601A2E3124001D63D2 /* friends.xcdatamodeld in Sources */, 10F2D1361A2E2AB000DDD58D /* Friend.swift in Sources */, + 024A45BD1A33AB1C00757D93 /* CalendarTabBarViewController.swift in Sources */, 10F2D1341A2E2A9600DDD58D /* FriendsTableViewController.swift in Sources */, 10F2D1321A2E29C300DDD58D /* EditFriendsTableViewController.swift in Sources */, 10F2D13C1A2E2AFA00DDD58D /* FriendDetailsTableViewController.swift in Sources */, 10F2D13E1A2E2B3400DDD58D /* FriendTableViewCell.swift in Sources */, + 024A45BB1A33AB0900757D93 /* CalendarTableViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/socialCalendar/Base.lproj/Miles.storyboard b/socialCalendar/Base.lproj/Miles.storyboard index 13dee81..cadaba8 100644 --- a/socialCalendar/Base.lproj/Miles.storyboard +++ b/socialCalendar/Base.lproj/Miles.storyboard @@ -1,25 +1,9 @@ - + - + - - - - - - - - - - - - - - - - @@ -55,6 +39,7 @@ + - + + + + + + + + + + + + + + + + + @@ -323,10 +324,10 @@ - + - + diff --git a/socialCalendar/CalendarTabBarViewController.swift b/socialCalendar/CalendarTabBarViewController.swift new file mode 100644 index 0000000..7a39bd9 --- /dev/null +++ b/socialCalendar/CalendarTabBarViewController.swift @@ -0,0 +1,35 @@ +// +// CalendarTabBarViewController.swift +// socialCalendar +// +// Created by Miles Crabill on 12/6/14. +// Copyright (c) 2014 AIT. All rights reserved. +// + +import UIKit + +class CalendarTabBarViewController: UITabBarController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/socialCalendar/CalendarTableViewController.swift b/socialCalendar/CalendarTableViewController.swift new file mode 100644 index 0000000..c0337e3 --- /dev/null +++ b/socialCalendar/CalendarTableViewController.swift @@ -0,0 +1,97 @@ +// +// CalendarTableViewController.swift +// socialCalendar +// +// Created by Miles Crabill on 12/6/14. +// Copyright (c) 2014 AIT. All rights reserved. +// + +import UIKit + +class CalendarTableViewController: UITableViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Uncomment the following line to preserve selection between presentations + // self.clearsSelectionOnViewWillAppear = false + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem() + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + // MARK: - Table view data source + + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + // #warning Potentially incomplete method implementation. + // Return the number of sections. + return 0 + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + // #warning Incomplete method implementation. + // Return the number of rows in the section. + return 0 + } + + /* + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell + + // Configure the cell... + + return cell + } + */ + + /* + // Override to support conditional editing of the table view. + override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { + // Return NO if you do not want the specified item to be editable. + return true + } + */ + + /* + // Override to support editing the table view. + override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { + if editingStyle == .Delete { + // Delete the row from the data source + tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) + } else if editingStyle == .Insert { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } + } + */ + + /* + // Override to support rearranging the table view. + override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { + + } + */ + + /* + // Override to support conditional rearranging of the table view. + override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { + // Return NO if you do not want the item to be re-orderable. + return true + } + */ + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/socialCalendar/Info.plist b/socialCalendar/Info.plist index 9589179..4318277 100644 --- a/socialCalendar/Info.plist +++ b/socialCalendar/Info.plist @@ -25,7 +25,7 @@ UILaunchStoryboardName LaunchScreen UIMainStoryboardFile - Kevin + Miles UIRequiredDeviceCapabilities armv7 diff --git a/socialCalendar/LoginViewController.swift b/socialCalendar/LoginViewController.swift index 47802d3..43cf532 100644 --- a/socialCalendar/LoginViewController.swift +++ b/socialCalendar/LoginViewController.swift @@ -22,7 +22,7 @@ class LoginViewController: UIViewController { loginUser() var currentUser = PFUser.currentUser() if currentUser != nil { - presentTabBarViewController() + performSegueWithIdentifier("login", sender: self) } } else { var errorPopup = UIAlertController(title: "Please enter a username and password.", message: nil, preferredStyle: .Alert) @@ -80,10 +80,8 @@ class LoginViewController: UIViewController { user.signUpInBackgroundWithBlock { success, error in - // TODO - // change if we modify class of the tab bar controller if success { - self.presentTabBarViewController() + performSegueWithIdentifier("login", sender: self) } else { var errorPopup = UIAlertController(title: "An error occurred while registering", message: error.localizedDescription, preferredStyle: .Alert) var okayActionInner = UIAlertAction(title: "Okay", style: .Default, handler: nil) @@ -97,20 +95,23 @@ class LoginViewController: UIViewController { presentViewController(signupPopup, animated: true, completion: nil) } - func presentTabBarViewController() { - var vc = self.storyboard?.instantiateViewControllerWithIdentifier("TabBarController") as UITabBarController - self.navigationController?.pushViewController(vc, animated: true) + func logout() { + PFUser.logOut() + self.navigationController?.popToRootViewControllerAnimated(true) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. + } + override func viewDidAppear(animated: Bool) { + super.viewDidAppear(animated) var currentUser = PFUser.currentUser() if currentUser != nil { // cached user logged in - presentTabBarViewController() + performSegueWithIdentifier("login", sender: self) } } @@ -120,14 +121,27 @@ class LoginViewController: UIViewController { } - /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. + if segue.identifier == "login" { + let vc = segue.destinationViewController as CalendarTabBarViewController + vc.navigationController?.navigationItem.backBarButtonItem = nil + vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Log Out", style: .Plain, target: self, action: "logout") + vc.navigationItem.title = "Logged in as " + PFUser.currentUser().username + } + } + + override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool { + // if no one is logged in, don't perform segue + if identifier == "login" && PFUser.currentUser() == nil { + return false + } + + return true } - */ } From be83314774bfa3a3a689a357561dbdeb473bbcf9 Mon Sep 17 00:00:00 2001 From: Miles Crabill Date: Tue, 9 Dec 2014 20:25:59 +0100 Subject: [PATCH 2/4] fixed missing self --- socialCalendar/Base.lproj/Kevin.storyboard | 4 ++-- socialCalendar/LoginViewController.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/socialCalendar/Base.lproj/Kevin.storyboard b/socialCalendar/Base.lproj/Kevin.storyboard index 8dad4df..54d622d 100644 --- a/socialCalendar/Base.lproj/Kevin.storyboard +++ b/socialCalendar/Base.lproj/Kevin.storyboard @@ -1,7 +1,7 @@ - + - + diff --git a/socialCalendar/LoginViewController.swift b/socialCalendar/LoginViewController.swift index 43cf532..9eaf22d 100644 --- a/socialCalendar/LoginViewController.swift +++ b/socialCalendar/LoginViewController.swift @@ -81,7 +81,7 @@ class LoginViewController: UIViewController { user.signUpInBackgroundWithBlock { success, error in if success { - performSegueWithIdentifier("login", sender: self) + self.performSegueWithIdentifier("login", sender: self) } else { var errorPopup = UIAlertController(title: "An error occurred while registering", message: error.localizedDescription, preferredStyle: .Alert) var okayActionInner = UIAlertAction(title: "Okay", style: .Default, handler: nil) From 705c49ad426d5adf8ec4865d9cbbe0277cd20f39 Mon Sep 17 00:00:00 2001 From: Miles Crabill Date: Tue, 9 Dec 2014 20:39:49 +0100 Subject: [PATCH 3/4] fixed ui, got rid of back button --- socialCalendar/LoginViewController.swift | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/socialCalendar/LoginViewController.swift b/socialCalendar/LoginViewController.swift index 9eaf22d..7959c62 100644 --- a/socialCalendar/LoginViewController.swift +++ b/socialCalendar/LoginViewController.swift @@ -20,10 +20,6 @@ class LoginViewController: UIViewController { if username != "" && password != "" { loginUser() - var currentUser = PFUser.currentUser() - if currentUser != nil { - performSegueWithIdentifier("login", sender: self) - } } else { var errorPopup = UIAlertController(title: "Please enter a username and password.", message: nil, preferredStyle: .Alert) var okayAction = UIAlertAction(title: "Okay", style: .Default, handler: nil) @@ -40,7 +36,7 @@ class LoginViewController: UIViewController { PFUser.logInWithUsernameInBackground(usernameTextField.text, password: passwordTextField.text) { user, error in if user != nil { - print("logged in") + self.performSegueWithIdentifier("login", sender: self) } else { var errorPopup = UIAlertController(title: "Login failed.", message: error.localizedDescription, preferredStyle: .Alert) var okayAction = UIAlertAction(title: "Okay", style: .Default, handler: nil) @@ -81,7 +77,7 @@ class LoginViewController: UIViewController { user.signUpInBackgroundWithBlock { success, error in if success { - self.performSegueWithIdentifier("login", sender: self) + self.performSegueWithIdentifier("login", sender: self.navigationController) } else { var errorPopup = UIAlertController(title: "An error occurred while registering", message: error.localizedDescription, preferredStyle: .Alert) var okayActionInner = UIAlertAction(title: "Okay", style: .Default, handler: nil) @@ -102,24 +98,18 @@ class LoginViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - - // Do any additional setup after loading the view. - } - - override func viewDidAppear(animated: Bool) { - super.viewDidAppear(animated) var currentUser = PFUser.currentUser() if currentUser != nil { // cached user logged in performSegueWithIdentifier("login", sender: self) } + // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } - // MARK: - Navigation @@ -129,7 +119,7 @@ class LoginViewController: UIViewController { // Pass the selected object to the new view controller. if segue.identifier == "login" { let vc = segue.destinationViewController as CalendarTabBarViewController - vc.navigationController?.navigationItem.backBarButtonItem = nil + vc.navigationController?.navigationItem.hidesBackButton = true vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Log Out", style: .Plain, target: self, action: "logout") vc.navigationItem.title = "Logged in as " + PFUser.currentUser().username } From b70ab09cdf3a211c25ea8b081390d5472468bb02 Mon Sep 17 00:00:00 2001 From: Miles Crabill Date: Tue, 9 Dec 2014 20:42:40 +0100 Subject: [PATCH 4/4] logout button moved to left --- socialCalendar/LoginViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/socialCalendar/LoginViewController.swift b/socialCalendar/LoginViewController.swift index 7959c62..8efdea9 100644 --- a/socialCalendar/LoginViewController.swift +++ b/socialCalendar/LoginViewController.swift @@ -15,6 +15,7 @@ class LoginViewController: UIViewController { @IBOutlet weak var messageLabel: UILabel! @IBAction func loginVerifyButton(sender: AnyObject) { + var username = usernameTextField.text var password = passwordTextField.text @@ -119,8 +120,8 @@ class LoginViewController: UIViewController { // Pass the selected object to the new view controller. if segue.identifier == "login" { let vc = segue.destinationViewController as CalendarTabBarViewController - vc.navigationController?.navigationItem.hidesBackButton = true - vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Log Out", style: .Plain, target: self, action: "logout") + vc.navigationItem.hidesBackButton = true + vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Log Out", style: .Plain, target: self, action: "logout") vc.navigationItem.title = "Logged in as " + PFUser.currentUser().username } }