我有一个UIVIEW控制器,允许我查看和编辑一个类的信息。
它只分配一次,但它的行数、节数和数据将根据用户选择的值传递给它。
例如。在这里它正在编辑一个name&type属性(表的头视图太大..我这样做,你会看到下面的怪异)
所以我输入一个名字,一切都显示良好。然后我单击address属性,现在详细视图如下所示:
到目前为止一切正常。如果单击“取消”并返回编辑“名称”属性,则显示“正常”。
问题是这个。我向下滚动地址表,如下所示:
然后单击“保存/取消”。现在,当我回去编辑Name属性时,TabLVIEW看起来就是这样!
就好像上一个表在表的头视图中仍然可见…?
我的视图将出现:这个UIVIEW控制器的方法如下:

- (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];

}
在这个表格看起来一团糟的图片中,cellforrowatindexpath方法只被调用了两次,尽管有3个可见的细胞(2个正常细胞和1个怪异细胞)。奇怪的单元格随着滚动而移动,仍然是可点击的。
我可以通过注释这个方法中的以下几行来解决这个问题。但是,我不想每次有人想要编辑一个细节时,都必须分配一个新的控制器:
    - (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;
}

最佳答案

如果不查看所有代码,很难说清楚,但是否有可能无法正确回收TableView单元格?必须为每个呈现不同的单元格分配不同的重用标识符。如果一个头单元被重用为一个细节单元(反之亦然),这将导致一些奇怪的渲染。

08-05 21:54