我有一个 UIViewController,它允许我查看和编辑类的信息。
它只分配一次,但它的行数、节数和数据会根据用户选择的值传递给它。
例如。这里它正在编辑一个名称和类型属性(表的标题 View 太大..我这样做是为了让你看到下面的奇怪之处)
所以我输入了一个名字,一切都显示正常。然后我单击地址属性,详细 View 现在如下所示:
到目前为止一切正常。如果我单击取消并返回编辑名称属性,它显示正常。 问题是这样的。我像这样向下滚动地址表:
然后点击保存/取消。现在,当我回去编辑 name 属性时,tableview 看起来像这样!
就好像之前的表格通过表格的标题 View 仍然可见......?
我的 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 个正常单元格和一个奇怪的单元格)。奇怪的单元格随着滚动而移动并且仍然可以点击。
我可以通过注释掉此方法中的以下行来解决此问题。但是,我不想每次有人想要编辑细节时都必须分配一个新的 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;
}
最佳答案
如果不查看所有代码很难判断,但您是否有可能没有正确回收 tableview 单元格?您必须为呈现不同的每个单元分配不同的 reuseIdentifier。如果标题单元格被重新用作详细信息单元格(反之亦然),这将导致渲染出现一些异常。
关于iphone - UITableView 怪异!带图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/556747/