我想創建一個手風琴類型的uitableviewcell,當用戶選擇單元格時,它展開顯示一個類似於digg應用程序的內嵌詳細信息視圖。我最初嘗試用cellForRowAtIndex中的customcell替換當前的tablecell,但是動畫看起來有點波濤洶涌,因爲您可以看到被替換的單元格,並且整體效果不能很好地工作。Accordion table cell - 如何動態擴展/收縮uitableviewcell?
如果你看看digg應用程序和其他誰做了這個似乎他們不是取代當前的單元格,而是可能添加一個子視圖到單元格?然而,原始單元格似乎根本不具有動畫效果,只有新的視圖才能進入表格。
有沒有人有任何想法如何實現類似的效果?
更新: 我一直在使用下面NEHA的方法,而小區動畫它肆虐,在表中的其他細胞的正確的方式取得了一些進展。我所做的是將UITableViewCell與包含UIView實例的自定義類進行子類化,該實例實際上繪製了視圖,然後將其添加到表格單元格contentview。
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
if (selected) {
[self expandCell];
}
}
-(void)expandCell {
self.contentView.frame = CGRectMake(0.0, 0.0, self.contentView.bounds.size.width, 110);
}
這裏是所有表委託方法我使用:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isSearching && indexPath.row == selectedIndex) {
static NSString *CellIdentifier = @"SearchCell";
CustomTableCell *cell = (CustomTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[cell setCustomTitle:[timeZoneNames objectAtIndex:indexPath.row] detail:[timeZoneNames objectAtIndex:indexPath.row]];
UILabel *theText = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 10.0, cell.contentView.bounds.size.width -20, 22.0)];
theText.text = @"Title Text";
[cell.contentView addSubview:theText];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10.0, 10 + 46.0, cell.contentView.bounds.size.width - 20, 40.0)];
textField.borderStyle = UITextBorderStyleLine;
[cell.contentView addSubview:textField];
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 88.0, cell.contentView.bounds.size.width - 20, 22.0)];
testLabel.text = [NSString stringWithFormat:@"Some text here"];
[cell.contentView addSubview:testLabel];
[theText release];
[textField release];
[testLabel release];
return cell;
} else {
static NSString *CellIdentifier = @"Cell";
CustomTableCell *cell = (CustomTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[cell setCustomTitle:[timeZoneNames objectAtIndex:indexPath.row] detail:[timeZoneNames objectAtIndex:indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
selectedIndex = indexPath.row;
isSearching = YES;
[tableView beginUpdates];
[tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isSearching && indexPath.row == selectedIndex) {
return 110;
}
return rowHeight;
}
現在看來,該小區正在擴大,但實際上沒有被刷新,從而被的arent所示的標籤和文本框。但是,當我將單元格關閉並在屏幕上滾動時,它們會顯示出來。
任何想法?
人時?不是在尋找詳細的代碼,而只是關於如何實現這一目標的一些指導方針? – 2010-06-18 04:06:18
你爲什麼不讓帕維爾的答案是正確的答案......你不能比這更好。 – 2013-11-15 03:52:27