UItable Cell Overflow ios

I am making an application that requires the expansion of onclick cells to show more details. I used a custom cell and added them to a UItableview. When I click on a cell, it animates the beautiful and goes down, and when I click again, it goes up, this is done using a change in the height of the cell. The actual size of user cells is larger than I usually show. When I click on a cell, the whole cell is displayed. Only problem I am facing is data overflow. this data should be hidden if the cell is not selected. Only when it is selected, data should be displayed.

I mentioned different articles, trying to change the binding of color settings, did not work for me. I have the same problem that the uitablecellview iphone overflow asked in this question, tried to answer, but that didn't work.

All I need to do is hide the bottom of the user cell when it is not expanded, and show it when it is expanded ...!

These are my screenshots.

When it is loaded When it is loaded When I click on a cell When I click on the cell] When I click on the 2nd cell When I click on the second cell When I click on the cell which is expanded
When I click on a cell that is already expanded These are the codes I used ....

// Declaring the SearchResultTable. CGRect filterFrame = CGRectMake(0,31, 320, 400); self.searchResultTable = [[UITableView alloc] initWithFrame:filterFrame]; self.searchResultTable.dataSource = self; self.searchResultTable.delegate = self; self.searchResultTable.backgroundColor = [UIColor whiteColor]; self.searchResultTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine; self.searchResultTable.separatorColor = [UIColor lightGrayColor]; [self.view addSubview:self.searchResultTable]; //Adding cells - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ExpandedSearchResultTableCell"; ExpandedSearchResultTableCell *cell = (ExpandedSearchResultTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell.contentView.clipsToBounds = YES; NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExpandedSearchResultTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } cell.productNameLable.text = @"Only this should be shown"; cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded"; cell.productApplicationLable.text=@ "This Should be hidden.. Only shown when expanded"; cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded"; cell.productQuantityLable.text=@ "This Should be hidden.. Only shown when expanded"; cell.productReactivityLable.text=@ "This Should be hidden.. Only shown when expanded";; return cell; } //on click event (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Deselect cell [tableView deselectRowAtIndexPath:indexPath animated:TRUE]; // Toggle 'selected' state BOOL isSelected = ![self cellIsSelected:indexPath]; // Store cell 'selected' state keyed on indexPath NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected]; [selectedIndexes setObject:selectedIndex forKey:indexPath]; // This is where magic happens... [searchResultTable beginUpdates]; [searchResultTable endUpdates]; } //Getting the height depending on expanded or not - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // If our cell is selected, return double height if([self cellIsSelected:indexPath]) { return kCellHeight * 3.0; } // Cell isn't selected so return single height return kCellHeight; } 
+6
source share
3 answers

Ok, I did this using a single flag and cell reference cellForRowAtIndexPath in the didSelectRowAtIndexPath file. And setting my plates visible and hidden according to crash and stretch. The flag is updated depending on whether the cell is selected or not ... !!

Thank you for helping everyone ..!

+1
source

If you are looking for a cell extension using a regular table type,

iPhone UITableView with animated expanding cells

And if in case you use a grouped table view and want to expand the selection of the section title,

Table animation and gestures

+1
source

Ooops, Downloading the code made your message dirty.

I do not view your code.

I will explain the logic to you.

  • Only this should be displayed in your indexpath.row = 0;
  • The number of rows in the section will be selected, and then the number of displayed cells + 1 else 1.
 cell.productNameLable.text = @"Only this should be shown"; cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded"; cell.productApplicationLable.text=@ "This Should be hidden.. Only shown when expanded"; cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded"; cell.productQuantityLable.text=@ "This Should be hidden.. Only shown when expanded"; cell.productReactivityLable.text=@ "This Should be hidden.. Only shown when expanded";; 

This makes your code dirty. If you want to show all the data in one cell, and only one cell is added when you select one section, I suggest adding all this to different cells.

I'm still confused why you do this long coding, Please refer to this answer for a better explanation

0
source

Source: https://habr.com/ru/post/924056/


All Articles