iphone – UITableView怪异!与图片

我有一个UIViewController,允许我查看和编辑类的信息.

它只分配一次,但它的行数,部分和数据将根据用户选择的值传递给它.

例如.在这里,它正在编辑一个名称&类型属性(表的标题视图太大..我这样做,所以你会看到下面的怪异)

所以我输入一个名字,一切都很好.然后我点击地址属性,细节视图现在看起来像这样:

到目前为止一切都好.如果我单击取消并返回编辑名称属性,它显示正常.
问题是这个.我像这样向下滚动地址表:

然后单击“保存/取消”.现在当我回去编辑name属性时,tableview看起来像这样!

就好像通过表格的标题视图仍然可以看到上一个表格.?

我的viewWillAppear:这个uiviewcontroller的方法如下所示:

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

}

在表格看起来混乱的图片中,即使有3个单元格可见(2个正常单元格和一个奇怪的单元格),也只会调用两次cellForRowAtIndexPath方法.怪异的单元格随着滚动而移动,仍然可以点击.

我可以通过在此方法中注释掉以下行来解决此问题.但是,每当有人想要编辑细节时我都不想分配新的控制器:

    - (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单元格吗?您必须为每个呈现不同的单元格分配不同的reuseIdentifier.如果标题单元格被重新用作细节单元格(反之亦然),那将导致渲染中的一些奇怪现象.

点赞