Advertisement
Guest User

Untitled

a guest
Nov 8th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1.  
  2. import Foundation
  3. import UIKit
  4. import MessageUI
  5.  
  6. class HomeScreenTableViewController: UITableViewController, MFMailComposeViewControllerDelegate
  7. {
  8. var myEmail: MFMailComposeViewController!
  9. var timelineData : NSMutableArray = NSMutableArray()
  10.  
  11. // override init (style: UITableViewStyle)
  12. // {
  13. // super.init(style: style)
  14. // //custom initialization
  15. // }
  16. //
  17. // required init(coder aDecoder: NSCoder)
  18. // {
  19. // super.init(coder: aDecoder)
  20. // //custom initialization
  21. // }
  22.  
  23. override func viewDidAppear(animated: Bool)
  24. {
  25. self.loadData()
  26. }
  27.  
  28. func loadData()
  29. {
  30. timelineData.removeAllObjects()
  31.  
  32. var findTimelineData : PFQuery = PFUser.query()
  33. findTimelineData.findObjectsInBackgroundWithBlock{
  34. (objects: [AnyObject]!, error: NSError!)-> Void in
  35. if error == nil
  36. {
  37. println("No error")
  38.  
  39. if let object = objects as? [PFObject!]
  40. {
  41. for object in objects
  42. {
  43. self.timelineData.addObject(object)
  44. }
  45. }
  46.  
  47. let array : NSArray = self.timelineData.reverseObjectEnumerator().allObjects
  48. self.timelineData = array as NSMutableArray
  49.  
  50. self.tableView.reloadData()
  51. }
  52.  
  53. }
  54. }
  55.  
  56. override func viewDidLoad()
  57. {
  58. super.viewDidLoad()
  59. // Uncomment the following line to preserve selection between presentations
  60. // self.clearsSelectionOnViewWillAppear = false
  61.  
  62. // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  63. // self.navigationItem.rightBarButtonItem = self.editButtonItem()
  64. }
  65.  
  66. override func didReceiveMemoryWarning()
  67. {
  68. super.didReceiveMemoryWarning()
  69. // Dispose of any resources that can be recreated.
  70. }
  71.  
  72. // MARK: - Table view data source
  73.  
  74. override func numberOfSectionsInTableView(tableView: UITableView) -> Int
  75. {
  76. // #warning Potentially incomplete method implementation.
  77. // Return the number of sections.
  78. return 1
  79. }
  80.  
  81. override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
  82. {
  83. // #warning Incomplete method implementation.
  84. // Return the number of rows in the section.
  85. return timelineData.count
  86. }
  87.  
  88. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
  89. {
  90. println("loading cell")
  91.  
  92. let postCell : LocationTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as LocationTableViewCell
  93.  
  94. let post : PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
  95.  
  96. postCell.imageView.image = post.objectForKey("currentLocation") as? UIImage
  97. postCell.userInfo.text = post.objectForKey("FirstLastName") as? String
  98.  
  99. // Configure the cell...
  100.  
  101. return postCell
  102. }
  103.  
  104. @IBAction func refresh()
  105. {
  106. tableView.reloadData()
  107. }
  108.  
  109. @IBAction func profile()
  110. {
  111. let viewController : UINavigationController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Profile Controller") as UINavigationController
  112.  
  113. self.presentViewController(viewController, animated: true, completion: nil)
  114. }
  115.  
  116. @IBAction func Friends()
  117. {
  118. let viewController : UINavigationController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Friend List Controller") as UINavigationController
  119. self.presentViewController(viewController, animated: true, completion: nil)
  120. }
  121.  
  122. @IBAction func LogOut()
  123. {
  124. PFUser.logOut()
  125. var currentUser = PFUser.currentUser() // this will now be nil
  126.  
  127. let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Login") as UIViewController
  128.  
  129. self.dismissViewControllerAnimated(true, completion: nil)
  130. }
  131.  
  132. @IBAction func settings()
  133. {
  134. let viewController : UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Settings") as UIViewController
  135.  
  136. self.presentViewController(viewController, animated: true, completion: nil)
  137. }
  138.  
  139. @IBAction func actionButton()
  140. {
  141. let alertController = UIAlertController(title: "What would you like to do?", message: "", preferredStyle: .ActionSheet)
  142.  
  143. let Ok = UIAlertAction(title: "Help", style: .Default)
  144. {
  145. UIAlertAction in
  146.  
  147. }
  148.  
  149. let Contact = UIAlertAction(title: "Contact Us", style: .Default)
  150. {
  151. UIAlertAction in
  152. self.SendEmail()
  153. }
  154. let Cancel = UIAlertAction(title: "Dismiss", style: .Default)
  155. {
  156. UIAlertAction in
  157.  
  158. }
  159.  
  160. alertController.addAction(Ok)
  161. alertController.addAction(Contact)
  162. alertController.addAction(Cancel)
  163.  
  164. self.presentViewController(alertController, animated: true, completion: nil)
  165. }
  166.  
  167. func SendEmail()
  168. {
  169. if(MFMailComposeViewController.canSendMail())
  170. {
  171. myEmail = MFMailComposeViewController()
  172. myEmail.mailComposeDelegate = self
  173.  
  174. //myEmail.mailComposeDelegate
  175.  
  176. var Subject = "Contact Testing"
  177. var recipients = ["geoffroy.guillaume@icloud.com"] //insert all recipient emails
  178. 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
  179.  
  180. myEmail.setSubject(Subject)
  181. myEmail.setToRecipients(recipients)
  182. myEmail.setMessageBody(bodyText, isHTML: true)
  183.  
  184. self.presentViewController(myEmail, animated: true, completion: nil)
  185. }
  186.  
  187. }
  188.  
  189. func mailComposeController(controller: MFMailComposeViewController!,
  190. didFinishWithResult result: MFMailComposeResult,
  191. error: NSError!)
  192. {
  193. switch(result.value)
  194. {
  195. case MFMailComposeResultSent.value:
  196. self.dismissViewControllerAnimated(true, completion: nil)
  197. sleep(1)
  198. let alertController = UIAlertController(title: "Thank You", message: "Thank you for contacting us, we will get back to you as soon as possible.", preferredStyle: .Alert)
  199.  
  200. let Dissmiss = UIAlertAction(title: "Dissmiss", style: .Default, handler: nil)
  201. alertController.addAction(Dissmiss)
  202.  
  203. presentViewController(alertController, animated: true, completion: nil)
  204. case MFMailComposeResultCancelled.value:
  205. self.dismissViewControllerAnimated(true, completion: nil)
  206. default:
  207. println("An error occured. Please try again.")
  208. }
  209.  
  210. self.dismissViewControllerAnimated(true, completion: nil)
  211.  
  212. }
  213.  
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement