我正在开发一个分组的UITableView,它有4个部分,每个部分有一行,并且对单元格有一个奇怪的行为。 细胞是普通的UITableViewCells,但细胞的高度约为60-80像素。 现在tableview使用圆角渲染单元格,但是当我选择单元格时,它们显示为蓝色,矩形。我不知道为什么单元格的行为是这样的,因为我有另一个分组的UITableView带有自定义单元格和88像素高度,这些单元格就像它们应该的那样工作。
如果我将高度更改为44像素的默认高度,则单元格的行为类似于应该。有谁知道这种行为,原因是什么?
就像我提到的那样,我没有做任何花哨的事情我在静态的,分组的UITableView中使用默认的UITableViewCells,其中4个部分在每个部分中有1行。
evangelion2100
编辑:好的,这是我的代码的相关部分。因为我只对这个tableview使用固定数量的单元格,所以我将单元格存储在2d NSMutableArray中。我在 - (void)viewDidLoad方法中设置了单元格,相应的委托方法使用存储的单元格访问数组。
如果细胞被选中,我没有看到任何会导致细胞奇怪行为的事情。
Edit2:很抱歉,我将单元格存储在数组中的原因不仅仅是单元格中的单元格。如果视图更改并且UITableView重新出现,则将使用自定义单元格交换单元格。这是存储细胞的真正原因。这就像某种“添加新电子邮件” - 行为类型,就像来自iPhone的联系人应用程序一样。
-(void)viewDidLoad {
// set up the AccompanyingLecture cell
UITableViewCell *accompanyingLectureCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"AccompanyingLectureCell"];
accompanyingLectureCell.textLabel.textAlignment = UITextAlignmentCenter;
accompanyingLectureCell.detailTextLabel.textAlignment = UITextAlignmentCenter;
accompanyingLectureCell.textLabel.text = NSLocalizedString(@"New Accompanying Lecture", @"");
accompanyingLectureCell.detailTextLabel.text = NSLocalizedString(@"Lecturer, Time, Location, etc.", @"");
accompanyingLectureCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
accompanyingLectureCell.frame = CGRectMake(0, 0, 320, 82);
// initialize datasource for all four sections
datasource = [[NSMutableArray alloc] initWithObjects:[NSMutableArray arrayWithObject:[lecturerCell autorelease]], [NSMutableArray arrayWithObject:[lectureDetailsCell autorelease]], [NSMutableArray arrayWithObject:[timeAndLocationCell autorelease]], [NSMutableArray arrayWithObject:[accompanyingLectureCell autorelease]], nil];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return [[datasource objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGRect currentFrame = [[[datasource objectAtIndex: indexPath.section] objectAtIndex:indexPath.row] frame];
return currentFrame.size.height;
}
答案 0 :(得分:0)
如果你只是在heightForRowAtIndexPath方法中返回82并且不在viewDidLoad中设置单元格的框架会发生什么?