UITableView weirdness! with photos

I have a UIViewController that allows me to view and edit class information.

It is allocated only once, but the number of rows, sections, and data is transferred to it, depending on the value that the user selected.

For instance. Here he edits the name and type property (the representation of the table title is too large. I did this for you to see weirdness below)

alt text

So, I enter a name and it all displays fine. Then I click on the address property, and now the detailed view looks like this:

alt text

Things are good. If I click cancel and return to edit the name property, it appears in order. The problem is this. I scroll through the address table like this:

alt text

And then click "Save / Cancel." Now, when I go back to change the name property, the table view looks like this:

alt text

As if the previous table is still visible as a table header.?

My viewWillAppear: the method for this uiviewcontroller is as follows:

- (void)viewWillAppear:(BOOL)animated { NSLog(@"Retain count of poolcopy is %d\n\n", [self.thePoolFacilityCopy retainCount] ); //This will be a reference to find our which pool Instance field we are editing. self.sectionFromParentTable = self.cellPath.section; //This will only be used by the arrays self.rowFromPreviousTable = self.cellPath.row; NSString *sectionName; switch (self.sectionFromParentTable) { case KNameIndex: sectionName = @"name"; break; case KAddressIndex: sectionName = @"address"; break; case KPhoneNumberIndex: sectionName = @"phone"; break; case KWebAddressIndex: sectionName = @"url"; break; case KPricesIndex: sectionName = @"prices"; break; case KPoolIndex: sectionName = @"pools"; default: break; } self.title = [NSString stringWithFormat:@"Editing %@", sectionName]; // use an empty view to position the cells in the vertical center of the portion of the view not covered by // the keyboard if (self.sectionFromParentTable == KPhoneNumberIndex || self.sectionFromParentTable == KWebAddressIndex) { UIView *singleSectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 60)]; self.theTableView.tableHeaderView = singleSectionHeaderView; [singleSectionHeaderView release]; self.theTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 10)]autorelease]; } else if (self.sectionFromParentTable == KAddressIndex) { UIView *addressHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 0)]; self.theTableView.tableHeaderView = addressHeaderView; [addressHeaderView release]; self.theTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 250)]autorelease]; } else if (self.sectionFromParentTable == KPoolIndex) { UIView *poolHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 2)]; self.theTableView.tableHeaderView = poolHeaderView; [poolHeaderView release]; self.theTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 10)]autorelease]; } else { UIView *doubleSectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)]; self.theTableView.tableHeaderView = doubleSectionHeaderView; [doubleSectionHeaderView release]; self.theTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 10)]autorelease]; } [self.theTableView reloadData]; 

}

In a picture where the table looks confused, the cellForRowAtIndexPath method is called only twice, although there are 3 cells visible (2 normal cells and one strange cell). The strange cell moves with the scroll and is still clickable.

I can fix this problem by commenting out the following lines of this method. However, I do not want each new controller to allocate a new controller:

  - (PoolFacilityDetailEditController *)childController { // Instantiate the editing view controller if necessary. // if (childController == nil) { PoolFacilityDetailEditController *controller = [[PoolFacilityDetailEditController alloc] initWithNibName:@"PoolFacilityDetailEditController" bundle:nil]; self.childController = controller; [controller release]; // } return childController; } 
+4
source share
2 answers

It's hard to say without looking at all the code, but is it possible that you are not properly processing your table cells? You must assign a different reuseIdentifier for each cell, which will be displayed differently. If the header cell is reused as a detailed cell (or vice versa), which will cause some oddities in the rendering.

+2
source

Use another class of TableViewCell, fully customize it according to your requirement. Then import this into your code. It is working!!

0
source

All Articles