2010-04-26 77 views
1

我正在一个分组的UITableView,有4个部分每节一行,并与单元格有奇怪的行为。 单元格是普通的UITableViewCells,但单元格的高度约为60 - 80像素。 现在桌面视图呈现单元正确与圆角,但是当我选择单元格时,它们显示为蓝色,并且矩形。我不知道为什么这些单元格的行为如此,因为我有另一个具有自定义单元格和88像素高度的分组UITableView,并且这些单元格像他们应该那样工作。UITableViewCell和分组UITableView奇怪的行为

如果我将高度更改为44像素的默认高度,那么单元格的行为就像应该一样。有谁知道这种行为,原因是什么?

就像我提到的,我没有做任何花哨的东西,我在一个静态的,分组的UITableView中使用默认的UITableViewCells,每节有1行4个部分。

evangelion2100

编辑: OK,这里是我的代码的相关部分。因为我只为这个tableview使用固定数量的单元格,所以我将这些单元格存储在一个2d NSMutableArray中。我在 - (void)viewDidLoad方法中设置了单元格,并且相应的委托方法使用存储的单元格访问Array。

我没有看到任何会导致这些单元格的奇怪行为,如果他们被选中。

编辑2:对不起,我将单元存储在数组中的原因不仅仅是单元之间的原因。如果视图更改并且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

它可能有助于发布您的'-tableView:cellForRowAtIndexPath:'方法以及任何其他触及单元格的委托方法,例如'-tableView:heightForRowAtIndexPath:' – 2010-04-26 07:23:36

回答

0

如果你只是在heightForRowAtIndexPath方法返回82,不设置单元格的框架在viewDidLoad中会发生什么?

+0

没有任何更改。如果我选择单元格,它会变成矩形。其实我尝试过不同的细胞高度,看它是否会起作用。但只有在像元高度为44像素时才会出现奇怪的行为。 – user325746 2010-04-26 10:38:52