我正在一個分組的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;
}
它可能有助於發佈您的'-tableView:cellForRowAtIndexPath:'方法以及任何其他觸及單元格的委託方法,例如'-tableView:heightForRowAtIndexPath:' – 2010-04-26 07:23:36