【问题标题】:UITableView weirdness! with picturesUITableView 怪异!有图片
【发布时间】:2009-02-17 13:20:18
【问题描述】:

我有一个 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];

}

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

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

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

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitableview


    【解决方案1】:

    如果不查看所有代码就很难判断,但是您是否有可能没有正确回收您的 tableview 单元格?您必须为呈现不同的每个单元格分配不同的重用标识符。如果标题单元格被重用为细节单元格(反之亦然),这将导致渲染出现一些异常。

    【讨论】:

      【解决方案2】:

      请使用 TableViewCell 的另一个类,根据您的要求完全自定义它。然后将其导入您的代码。有用!!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-15
        • 1970-01-01
        • 2012-01-06
        • 1970-01-01
        相关资源
        最近更新 更多