Iphone 真奇怪!带着照片

Iphone 真奇怪!带着照片,iphone,objective-c,cocoa-touch,uitableview,Iphone,Objective C,Cocoa Touch,Uitableview,我有一个UIViewController,它允许我查看和编辑类的信息 它只分配一次,但它的行数、节数和数据将根据用户选择的值传递给它 比如说。在这里,它正在编辑一个名称和类型属性(表的标题视图太大了..我这样做是为了让你看到下面的奇怪之处) 所以我输入了一个名字,它显示的很好。然后单击address属性,详细视图现在如下所示: - (void)viewWillAppear:(BOOL)animated { NSLog(@"Retain count of poolcopy is %d\n\n"

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

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

比如说。在这里,它正在编辑一个名称和类型属性(表的标题视图太大了..我这样做是为了让你看到下面的奇怪之处)

所以我输入了一个名字,它显示的很好。然后单击address属性,详细视图现在如下所示:

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

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

然后单击保存/取消。现在,当我返回编辑name属性时,tableview如下所示

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

My ViewWillDisplay:此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];
}

在表格看起来一团糟的图片中,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单元格?必须为每个呈现方式不同的单元格指定不同的reuseIdentifier。如果标题单元格被重新用作详细信息单元格(反之亦然),则在渲染时会出现一些异常。

请使用TableViewCell的另一个类,根据需要完全自定义它。然后将其导入到代码中。它起作用了