Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import UIKit
  2.  
  3.  
  4. protocol createStoryCellDelegate {
  5. func didRecord(sender: UIButton, storyItem: StoryItem)
  6. }
  7.  
  8. class CreateStoryCell: UITableViewCell {
  9.  
  10.  
  11. @IBOutlet weak var storyCellBackground: UIView!
  12.  
  13.  
  14. @IBOutlet weak var storyTextLabel: UILabel!
  15.  
  16.  
  17. @IBOutlet weak var record: UIButton!
  18.  
  19. var storyItem : StoryItem!
  20. var delegate: createStoryCellDelegate?
  21.  
  22. func setStoryItem(storyPart: StoryItem) {
  23. storyItem = storyPart
  24. storyTextLabel.text = storyItem.text
  25.  
  26. }
  27.  
  28. @IBAction func recordTapped(_ sender: UIButton) {
  29.  
  30. delegate?.didRecord(sender: sender, storyItem: storyItem)
  31. }
  32.  
  33. }
  34.  
  35. extension CreateStoryViewController : UITableViewDataSource {
  36.  
  37.  
  38. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  39.  
  40. let cell = tableView.dequeueReusableCell(withIdentifier: "createStoryCell", for: indexPath) as! CreateStoryCell
  41.  
  42. let storyItem = storyText?[indexPath.row]
  43.  
  44. cell.setStoryItem(storyPart: storyItem!)
  45.  
  46. cell.delegate = self
  47.  
  48. return cell
  49. }
  50.  
  51.  
  52. }
  53.  
  54. extension CreateStoryViewController : createStoryCellDelegate {
  55.  
  56. func didRecord(sender: UIButton, storyItem: StoryItem) {
  57.  
  58. if recordToggle == 1 {
  59.  
  60. sender.setImage(UIImage(named: "recordStop"), for: .normal)
  61.  
  62. checkRecording(storyItem: storyItem)
  63.  
  64. audioRecorder.record()
  65.  
  66. recordToggle = 2
  67.  
  68.  
  69. } else {
  70.  
  71. sender.setImage(UIImage(named: "smallMicBtn"), for: .normal)
  72.  
  73. audioRecorder.stop()
  74.  
  75. recordToggle = 1
  76.  
  77.  
  78. }
  79.  
  80. }
  81.  
  82. }
  83.  
  84. // let buttonPosition:CGPoint = sender.convert(CGPoint.zero, to: self.createStoryTableView)
  85. // let indexPath = self.createStoryTableView.indexPathForRow(at: buttonPosition)
  86. // let storyItem = self.storyText?[indexPath?.row ?? 0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement