Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import UIKit
- import MessageUI
- class HomeScreenTableViewController: UITableViewController, MFMailComposeViewControllerDelegate
- {
- var myEmail: MFMailComposeViewController!
- var timelineData : NSMutableArray = NSMutableArray()
- // override init (style: UITableViewStyle)
- // {
- // super.init(style: style)
- // //custom initialization
- // }
- //
- // required init(coder aDecoder: NSCoder)
- // {
- // super.init(coder: aDecoder)
- // //custom initialization
- // }
- override func viewDidAppear(animated: Bool)
- {
- self.loadData()
- }
- func loadData()
- {
- timelineData.removeAllObjects()
- var findTimelineData : PFQuery = PFUser.query()
- findTimelineData.findObjectsInBackgroundWithBlock{
- (objects: [AnyObject]!, error: NSError!)-> Void in
- if error == nil
- {
- println("No error")
- if let object = objects as? [PFObject!]
- {
- for object in objects
- {
- self.timelineData.addObject(object)
- }
- }
- let array : NSArray = self.timelineData.reverseObjectEnumerator().allObjects
- self.timelineData = array as NSMutableArray
- self.tableView.reloadData()
- }
- }
- }
- 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 1
- }
- override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
- {
- // #warning Incomplete method implementation.
- // Return the number of rows in the section.
- return timelineData.count
- }
- override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
- {
- println("loading cell")
- let postCell : LocationTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as LocationTableViewCell
- let post : PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
- postCell.imageView.image = post.objectForKey("currentLocation") as? UIImage
- postCell.userInfo.text = post.objectForKey("FirstLastName") as? String
- // Configure the cell...
- return postCell
- }
- @IBAction func refresh()
- {
- tableView.reloadData()
- }
- @IBAction func profile()
- {
- let viewController : UINavigationController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Profile Controller") as UINavigationController
- self.presentViewController(viewController, animated: true, completion: nil)
- }
- @IBAction func Friends()
- {
- let viewController : UINavigationController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Friend List Controller") as UINavigationController
- self.presentViewController(viewController, animated: true, completion: nil)
- }
- @IBAction func LogOut()
- {
- PFUser.logOut()
- var currentUser = PFUser.currentUser() // this will now be nil
- let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Login") as UIViewController
- self.dismissViewControllerAnimated(true, completion: nil)
- }
- @IBAction func settings()
- {
- let viewController : UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Settings") as UIViewController
- self.presentViewController(viewController, animated: true, completion: nil)
- }
- @IBAction func actionButton()
- {
- let alertController = UIAlertController(title: "What would you like to do?", message: "", preferredStyle: .ActionSheet)
- let Ok = UIAlertAction(title: "Help", style: .Default)
- {
- UIAlertAction in
- }
- let Contact = UIAlertAction(title: "Contact Us", style: .Default)
- {
- UIAlertAction in
- self.SendEmail()
- }
- let Cancel = UIAlertAction(title: "Dismiss", style: .Default)
- {
- UIAlertAction in
- }
- alertController.addAction(Ok)
- alertController.addAction(Contact)
- alertController.addAction(Cancel)
- self.presentViewController(alertController, animated: true, completion: nil)
- }
- func SendEmail()
- {
- if(MFMailComposeViewController.canSendMail())
- {
- myEmail = MFMailComposeViewController()
- myEmail.mailComposeDelegate = self
- //myEmail.mailComposeDelegate
- var Subject = "Contact Testing"
- var recipients = ["geoffroy.guillaume@icloud.com"] //insert all recipient emails
- var bodyText = "This is a test email sent from the currently developing iOS App: Primal Manufacturing. Please do not reply to this email." //insert body of email
- myEmail.setSubject(Subject)
- myEmail.setToRecipients(recipients)
- myEmail.setMessageBody(bodyText, isHTML: true)
- self.presentViewController(myEmail, animated: true, completion: nil)
- }
- }
- func mailComposeController(controller: MFMailComposeViewController!,
- didFinishWithResult result: MFMailComposeResult,
- error: NSError!)
- {
- switch(result.value)
- {
- case MFMailComposeResultSent.value:
- self.dismissViewControllerAnimated(true, completion: nil)
- sleep(1)
- let alertController = UIAlertController(title: "Thank You", message: "Thank you for contacting us, we will get back to you as soon as possible.", preferredStyle: .Alert)
- let Dissmiss = UIAlertAction(title: "Dissmiss", style: .Default, handler: nil)
- alertController.addAction(Dissmiss)
- presentViewController(alertController, animated: true, completion: nil)
- case MFMailComposeResultCancelled.value:
- self.dismissViewControllerAnimated(true, completion: nil)
- default:
- println("An error occured. Please try again.")
- }
- self.dismissViewControllerAnimated(true, completion: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement