Guest User

Untitled

a guest
Jul 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. [tableView visibleCells]
  2.  
  3. -(NSArray *)cellsForTableView:(UITableView *)tableView
  4. {
  5. NSInteger sections = tableView.numberOfSections;
  6. NSMutableArray *cells = [[NSMutableArray alloc] init];
  7. for (int section = 0; section < sections; section++) {
  8. NSInteger rows = [tableView numberOfRowsInSection:section];
  9. for (int row = 0; row < rows; row++) {
  10. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
  11. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; // **here, for those cells not in current screen, cell is nil**
  12. [cells addObject:cell];
  13. }
  14. }
  15. return cells;
  16. }
  17.  
  18. func getAllCells() -> [UITableViewCell] {
  19.  
  20. var cells = [UITableViewCell]()
  21. // assuming tableView is your self.tableView defined somewhere
  22. for i in 0...tableView.numberOfSections-1
  23. {
  24. for j in 0...tableView.numberOfRowsInSection(i)-1
  25. {
  26. if let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: j, inSection: i)) {
  27.  
  28. cells.append(cell)
  29. }
  30.  
  31. }
  32. }
  33. return cells
  34. }
  35.  
  36. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  37. {
  38. CustomCell *Cell = [self dequeueReusableCellWithIdentifier:@"Custom_Cell_Id"];
  39. if (Cell == NULL)
  40. {
  41. Cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Custom_Cell_Id"]];
  42. [Cells_Array addObject:Cell];
  43. }
  44. }
  45.  
  46. - (void) DoSomething
  47. {
  48. for (int i = 0;i < [Cells count];i++)
  49. {
  50. CustomCell *Cell = [Cells objectAtIndex:i];
  51. //Access cell components
  52. }
  53. }
  54.  
  55. -(UITableViewCell) cellForRowAtIndexPath (NSIndexPath *)indexPath
  56.  
  57. /// Reference to all cells.
  58. private var allCells = Set<UITableViewCell>()
  59.  
  60. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  61. let cell = tableView.dequeueReusableCell(withIdentifier: "Your_Cell_ID") as! UITableViewCell
  62. if !allCells.contains(cell) { allCells.insert(cell) }
  63. return cell
  64. }
  65.  
  66. extension UITableViewDataSource where Self:UITableView {
  67. /**
  68. * EXAMPLE: tableView.cells//list of cells in a tableview
  69. */
  70. var cells:[UITableViewCell] {
  71. return (0..<self.numberOfSections).indices.map { (sectionIndex:Int) -> [UITableViewCell] in
  72. return (0..<self.numberOfRows(inSection: sectionIndex)).indices.compactMap{ (rowIndex:Int) -> UITableViewCell? in
  73. return self.cellForRow(at: IndexPath(row: rowIndex, section: sectionIndex))
  74. }
  75. }.flatMap{$0}
  76. }
  77. }
  78.  
  79. self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.contentSize.width, self.tableView.contentSize.height);
  80.  
  81. -(NSMutableArray *)cellsForTableView:(UITableView *)tableView
  82. {
  83. NSMutableArray *cells = [[NSMutableArray alloc] init];
  84.  
  85. //Need to total each section
  86. for (int i = 0; i < [tableView numberOfSections]; i++)
  87. {
  88. NSInteger rows = [tableView numberOfRowsInSection:i];
  89. for (int row = 0; row < rows; row++) {
  90. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:i];
  91. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  92. for (UIView *subView in cell.subviews)
  93. {
  94. if ([subView isKindOfClass:[UITextField class]]){
  95. UITextField *txtField = (UITextField *)subView;
  96. [cells addObject:txtField.text];
  97.  
  98. }
  99. }
  100.  
  101. }
  102.  
  103. }
  104. return cells;
  105.  
  106. -(void) reloadViewHeight
  107. {
  108. float currentTotal = 0;
  109.  
  110. //Need to total each section
  111. for (int i = 0; i < [self.tableView numberOfSections]; i++)
  112. {
  113. CGRect sectionRect = [self.tableView rectForSection:i];
  114. currentTotal += sectionRect.size.height;
  115. }
  116.  
  117. //Set the contentSizeForViewInPopover
  118. self.contentSizeForViewInPopover = CGSizeMake(self.tableView.frame.size.width, currentTotal);
Add Comment
Please, Sign In to add comment