Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [tableView visibleCells]
- -(NSArray *)cellsForTableView:(UITableView *)tableView
- {
- NSInteger sections = tableView.numberOfSections;
- NSMutableArray *cells = [[NSMutableArray alloc] init];
- for (int section = 0; section < sections; section++) {
- NSInteger rows = [tableView numberOfRowsInSection:section];
- for (int row = 0; row < rows; row++) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
- UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; // **here, for those cells not in current screen, cell is nil**
- [cells addObject:cell];
- }
- }
- return cells;
- }
- func getAllCells() -> [UITableViewCell] {
- var cells = [UITableViewCell]()
- // assuming tableView is your self.tableView defined somewhere
- for i in 0...tableView.numberOfSections-1
- {
- for j in 0...tableView.numberOfRowsInSection(i)-1
- {
- if let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: j, inSection: i)) {
- cells.append(cell)
- }
- }
- }
- return cells
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CustomCell *Cell = [self dequeueReusableCellWithIdentifier:@"Custom_Cell_Id"];
- if (Cell == NULL)
- {
- Cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Custom_Cell_Id"]];
- [Cells_Array addObject:Cell];
- }
- }
- - (void) DoSomething
- {
- for (int i = 0;i < [Cells count];i++)
- {
- CustomCell *Cell = [Cells objectAtIndex:i];
- //Access cell components
- }
- }
- -(UITableViewCell) cellForRowAtIndexPath (NSIndexPath *)indexPath
- /// Reference to all cells.
- private var allCells = Set<UITableViewCell>()
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "Your_Cell_ID") as! UITableViewCell
- if !allCells.contains(cell) { allCells.insert(cell) }
- return cell
- }
- extension UITableViewDataSource where Self:UITableView {
- /**
- * EXAMPLE: tableView.cells//list of cells in a tableview
- */
- var cells:[UITableViewCell] {
- return (0..<self.numberOfSections).indices.map { (sectionIndex:Int) -> [UITableViewCell] in
- return (0..<self.numberOfRows(inSection: sectionIndex)).indices.compactMap{ (rowIndex:Int) -> UITableViewCell? in
- return self.cellForRow(at: IndexPath(row: rowIndex, section: sectionIndex))
- }
- }.flatMap{$0}
- }
- }
- self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.contentSize.width, self.tableView.contentSize.height);
- -(NSMutableArray *)cellsForTableView:(UITableView *)tableView
- {
- NSMutableArray *cells = [[NSMutableArray alloc] init];
- //Need to total each section
- for (int i = 0; i < [tableView numberOfSections]; i++)
- {
- NSInteger rows = [tableView numberOfRowsInSection:i];
- for (int row = 0; row < rows; row++) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:i];
- UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- for (UIView *subView in cell.subviews)
- {
- if ([subView isKindOfClass:[UITextField class]]){
- UITextField *txtField = (UITextField *)subView;
- [cells addObject:txtField.text];
- }
- }
- }
- }
- return cells;
- -(void) reloadViewHeight
- {
- float currentTotal = 0;
- //Need to total each section
- for (int i = 0; i < [self.tableView numberOfSections]; i++)
- {
- CGRect sectionRect = [self.tableView rectForSection:i];
- currentTotal += sectionRect.size.height;
- }
- //Set the contentSizeForViewInPopover
- self.contentSizeForViewInPopover = CGSizeMake(self.tableView.frame.size.width, currentTotal);
Add Comment
Please, Sign In to add comment