Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. static NSString* reuseIdentifier = @"Cell";
  2. UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  3. if(!cell)
  4. {
  5. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
  6. }
  7.  
  8. tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier: "Cell")
  9.  
  10. let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
  11.  
  12. var cell :UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
  13.  
  14. var cell:UITableViewCell? =
  15. tableView?.dequeueReusableCellWithIdentifier(reuseIdentifier) as? UITableViewCell
  16. if (cell == nil)
  17. {
  18. cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,
  19. reuseIdentifier: reuseIdentifier)
  20. }
  21. // At this point, we definitely have a cell -- either dequeued or newly created,
  22. // so let's force unwrap the optional into a UITableViewCell
  23. cell!.detailTextLabel.text = "some text"
  24.  
  25. return cell
  26.  
  27. let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) ?? UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
  28.  
  29. cell.detailTextLabel?.text = "some text"
  30.  
  31. return cell
  32.  
  33. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) ?? UITableViewCell(style: .subtitle, reuseIdentifier: cellIdentifier)
  34.  
  35. cell.detailTextLabel?.text = ""
  36.  
  37. return cell
  38.  
  39. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  40.  
  41. let cell: UITableViewCell = {
  42. guard let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell") else {
  43. // Never fails:
  44. return UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "UITableViewCell")
  45. }
  46. return cell
  47. }()
  48.  
  49. // (cell is non-optional; no need to use ?. or !)
  50.  
  51. // Configure your cell:
  52. cell.textLabel?.text = "Key"
  53. cell.detailTextLabel?.text = "Value"
  54.  
  55. return cell
  56. }
  57.  
  58. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  59. let reuseIdentifier = "cell"
  60. var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as UITableViewCell?
  61. if (cell == nil) {
  62. cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: reuseIdentifier)
  63. }
  64. cell!.textLabel?.text = self.items[indexPath.row]
  65. cell!.detailTextLabel?.text = self.items[indexPath.row]
  66. return cell!
  67. }
  68.  
  69. let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as? UITableViewCell ?? UITableViewCell(style: .Subtitle,
  70. reuseIdentifier: reuseIdentifier)
  71.  
  72. cell.detailTextLabel?.text = "some text"
  73.  
  74. return cell
  75.  
  76. func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
  77. {
  78. let cell = tableView .dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
  79. cell.textLabel.text = String(format: "%i", indexPath.row+1)
  80. // set any other property of your cell here
  81. return cell
  82. }
  83.  
  84. if !cell { .....
  85.  
  86. if cell == nil { ...
  87.  
  88. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:
  89. NSIndexPath) -> UITableViewCell {
  90. var CellIdentifier:String = "Cell"
  91. var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(CellIdentifier) as? UITableViewCell
  92. if cell == nil {
  93. cell = UITableViewCell(style:UITableViewCellStyle(rawValue:3)!,reuseIdentifier:CellIdentifier)
  94. }
  95. return cell!
  96. }
  97.  
  98. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  99. let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: cellId)
  100. let user = users[indexPath.row]
  101. cell.textLabel?.text = user.name
  102. cell.detailTextLabel?.text = user.email
  103. return cell
  104. }
  105.  
  106. var cell = tableView.dequeueReusableCell(withIdentifier: yourCellReuseIdentifier, for: indexPath)
  107.  
  108. if cell.detailTextLabel == nil {
  109. cell = UITableViewCell(style: .value1, reuseIdentifier: repeatCellReuseIdentifier)
  110. }
  111.  
  112. cell.textLabel?.text = "Title"
  113. cell.detailTextLabel?.text = "Detail"
  114.  
  115. return cell
  116.  
  117. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
  118. {
  119.  
  120. var cell:UITableViewCell? =
  121. tableView.dequeueReusableCell(withIdentifier: "cell")
  122. if (cell != nil)
  123. {
  124. cell = UITableViewCell(style: UITableViewCellStyle.subtitle,
  125. reuseIdentifier: "cell")
  126. }
  127. cell!.textLabel?.text = "ABC"
  128. cell!.detailTextLabel?.text = "XYZ"
  129.  
  130. return cell!
  131.  
  132. }
  133.  
  134. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  135. let cell = tableView.dequeueReusableCell(withIdentifier: "My Reuse Identifier", for: indexPath)
  136.  
  137. cell.textLabel?.text = "Key"
  138. cell.detailTextLabel?.text = "Value"
  139.  
  140. return cell
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement