我想有相同的行爲Twitter的應用程序選擇鳴叫那就是當:擴大該行並添加補充內容。IOS - 展開表視圖細胞像Twitter的應用程序
所以這不僅是一個基本的行大小調整。我想我需要2個不同的定製單元,所以我做了這樣的事情:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath compare:self.selectedIndexPath] != NSOrderedSame) {
FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FirstCell"];
if (!cell) {
cell = [[FirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FirstCell"];
}
cell.firstnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"firstname"];
return cell;
}
else {
SecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SecondCell"];
if (!cell) {
cell = [[SecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SecondCell"];
}
cell.firstnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"firstname"];
cell.lastnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"lastname"];
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath compare:self.selectedIndexPath] == NSOrderedSame) {
return 80.0;
} else {
return 44.0;
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedIndexPath = indexPath;
[tableView reloadData];
}
我在這裏的問題是,我想保持像Twitter的應用程序的流體動畫這不是我的情況,因爲[tableView reloadData]
(這是強制性的我認爲,因爲我有2個不同的自定義單元格)。
因此,任何人知道的解決方法,我需要或也許有人知道Twitter的應用程序是如何處理這個動畫的東西?
這裏的問題是,當我選擇了某一行,其他的人都保持'SecondCell'類,因爲它們沒有重新加載(只有細胞體積變化)。這就是爲什麼我調用'[tableView reloadData]'。但是如果我用'beginUpdates/endUpdates'包圍'[tableView reloadData]',那麼根本就沒有動畫。任何解決方案? – Yaman 2013-02-19 21:38:43
嗯,是否有可能擁有相同類型的單元格並對高度和佈局進行一些動態計算?我前一段時間寫過這篇文章:http://www.roostersoftstudios.com/2011/04/14/iphone-uitableview-with-animated-expanding-cells/ – rooster117 2013-02-19 21:41:24
其實我在發佈之前看過你的博客,但這並不完全是我想這樣做,因爲您只是根據文本重新調整標籤大小,然後根據標籤大小調整單元格大小。但在我的情況下,我想添加一些UIButton,UIImageView等,這就是爲什麼我認爲需要2個自定義單元格。 – Yaman 2013-02-19 21:47:23