Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. func updateCell(path:Int){
  2. self.data = self.getData.feed
  3. let indexPath = NSIndexPath(forRow: path, inSection: 0)
  4.  
  5. self.tableView.beginUpdates()
  6. self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade) //try other animations
  7. self.tableView.endUpdates()
  8. }
  9.  
  10. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  11. var cell:PhotoCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PhotoCell
  12.  
  13. if data[indexPath.row].objectId == ""{
  14. //getData.getData(self, cellId: indexPath.row)
  15. getData.FeedQueue(self, cellId: indexPath.row)
  16. }else if data[indexPath.row].loading == 0{
  17. getData.FeedQueue(self, cellId: indexPath.row)
  18. }else{
  19. if Coz().CheckSystemVersion("8.0"){
  20. var subviews = cell.subviews
  21. for view in subviews{
  22. view.removeFromSuperview()
  23. }
  24. }else{
  25. for view in cell.contentView.subviews{
  26. if view.isKindOfClass(UIView){
  27. view.removeFromSuperview()
  28. }
  29. }
  30. }
  31. }
  32.  
  33. let screenSize: CGRect = UIScreen.mainScreen().bounds
  34. let screenWidth = screenSize.width;
  35. var rect = CGRectMake(0, 0, screenWidth, screenWidth)
  36.  
  37. var imageSizes:CGFloat = 40
  38.  
  39. let imgButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
  40. imgButton.tag = indexPath.row
  41. imgButton.frame = rect
  42. imgButton.setBackgroundImage(data[indexPath.row].file, forState: .Normal)
  43. imgButton.addTarget(self, action: "imgButton:", forControlEvents: UIControlEvents.TouchUpInside)
  44. cell.addSubview(imgButton)
  45.  
  46. var sumLike = data[indexPath.row].likeCount - data[indexPath.row].dislikeCount
  47. cell.setTableUp(data[indexPath.row].file, tTag:indexPath.row, screenWidth:screenWidth, commentCount:data[indexPath.row].commentCount, sumLikeCount:sumLike, identification:data[indexPath.row].objectId, sender:self, feed:data[indexPath.row], from:"FeedVC")
  48.  
  49. return cell
  50. }
  51.  
  52.  
  53.  
  54. ////////
  55. PhotoCell class
  56. ///////
  57. var IdOfObject:String = ""
  58. var senderView:AnyObject!
  59. var cellData:FeedData!
  60. var cellTag:Int!
  61. var fromView:String!
  62. var thisImage:UIImage!
  63.  
  64. override func awakeFromNib() {
  65. super.awakeFromNib()
  66. }
  67.  
  68. override func setSelected(selected: Bool, animated: Bool) {
  69. super.setSelected(selected, animated: animated)
  70. // Configure the view for the selected state
  71. }
  72.  
  73. func setTableUp(tImage:UIImage, tTag:Int, screenWidth:CGFloat, commentCount: Int, sumLikeCount:Int, identification:String, sender:AnyObject, feed:FeedData, from:String){
  74.  
  75. thisImage = tImage
  76. fromView = from
  77. cellTag = tTag
  78. cellData = feed
  79. senderView = sender
  80. IdOfObject = identification
  81. backgroundColor = Coz.GlobalVariables.ThemeSecondColor
  82. var rect = CGRectMake(0, 0, screenWidth, screenWidth + 38)
  83. frame = rect
  84. var imageSizes:CGFloat = 30
  85. var imageTintColors:UIColor = Coz.GlobalVariables.ThemeColor
  86.  
  87. var clickedId = IdOfObject
  88. var idForUserDefaults = "p" + clickedId
  89. var userDefaults = NSUserDefaults.standardUserDefaults()
  90. var defaultValue: AnyObject? = userDefaults.valueForKey(idForUserDefaults)
  91.  
  92. //Control Bar Under The Picture
  93. var controlBar:UIView = UIView(frame: CGRectMake(0, screenWidth, screenWidth, 38))
  94.  
  95. //Like Up Button
  96. let upButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
  97. upButton.tag = tTag
  98. upButton.frame = CGRectMake(10, 5, imageSizes, imageSizes)
  99. upButton.tintColor = imageTintColors
  100. upButton.setImage(UIImage(named: "up.png"), forState: UIControlState.Normal)
  101. upButton.addTarget(self, action: "upButtonAction:", forControlEvents: UIControlEvents.TouchUpInside)
  102. if defaultValue?.integerValue == 1{
  103. upButton.tintColor = UIColor.blueColor()
  104. }
  105. controlBar.addSubview(upButton)
  106.  
  107. //Like Count Label
  108. let likeCount = UILabel(frame: CGRectMake(40, 5, imageSizes, imageSizes))
  109. likeCount.textColor = imageTintColors
  110. likeCount.text = String(sumLikeCount)
  111. likeCount.font = UIFont(name: Coz.GlobalVariables.ThemeFontName, size: 17)
  112. likeCount.textAlignment = NSTextAlignment.Center
  113. controlBar.addSubview(likeCount)
  114.  
  115. //Like Down Button
  116. let downButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
  117. downButton.tag = tTag
  118. downButton.frame = CGRectMake(70, 5, imageSizes, imageSizes)
  119. downButton.tintColor = imageTintColors
  120. downButton.setImage(UIImage(named: "down.png"), forState: UIControlState.Normal)
  121. downButton.addTarget(self, action: "downButtonAction:", forControlEvents: UIControlEvents.TouchUpInside)
  122. if defaultValue?.integerValue == -1{
  123. downButton.tintColor = UIColor.blueColor()
  124. }
  125. controlBar.addSubview(downButton)
  126.  
  127. //Comment Button
  128. let commentButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
  129. commentButton.tag = tTag
  130. commentButton.frame = CGRectMake(screenWidth - screenWidth/5 - 25 - imageSizes, 5, imageSizes, imageSizes)
  131. commentButton.tintColor = imageTintColors
  132. commentButton.setImage(UIImage(named: "comment.png"), forState: UIControlState.Normal)
  133. commentButton.addTarget(self, action: "commentButtonAction:", forControlEvents: UIControlEvents.TouchUpInside)
  134. controlBar.addSubview(commentButton)
  135.  
  136. //Comment Count Label
  137. let commentCountLabel = UILabel(frame: CGRectMake(screenWidth - screenWidth/5 - 25 - imageSizes, 2.5, imageSizes, imageSizes))
  138. commentCountLabel.textColor = imageTintColors
  139. commentCountLabel.text = String(commentCount)
  140. commentCountLabel.textAlignment = NSTextAlignment.Center
  141. commentCountLabel.font = UIFont(name: Coz.GlobalVariables.ThemeFontName, size: 17)
  142. controlBar.addSubview(commentCountLabel)
  143.  
  144. //Share Button
  145. let shareButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
  146. shareButton.tag = tTag
  147. shareButton.frame = CGRectMake(screenWidth - screenWidth/5 - 10, 4, screenWidth/5, imageSizes)
  148. shareButton.tintColor = imageTintColors
  149. shareButton.backgroundColor = Coz.GlobalVariables.ThemeColor
  150. shareButton.setTitle(NSLocalizedString("shareButton", comment: ""), forState: UIControlState.Normal)
  151. shareButton.setTitleColor(backgroundColor, forState: UIControlState.Normal)
  152. shareButton.titleLabel?.font = UIFont(name: Coz.GlobalVariables.ThemeFontName, size: 17)
  153. shareButton.addTarget(self, action: "shareButtonAction:", forControlEvents: UIControlEvents.TouchUpInside)
  154. shareButton.layer.cornerRadius = 5
  155. shareButton.clipsToBounds = true
  156. controlBar.addSubview(shareButton)
  157. addSubview(controlBar)
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement