[英]Can't Reorder a UITableViewCell into _some_ empty sections of a UITableView
如果我在編輯模式下有一個UITableView,並且啟用了重新排序,則似乎無法將某些(但不是全部)單元格移到某些(但不是全部)空節中。 例如,如果我有這樣的布局:
Section 1
apple
banana
Section 2
doberman
Section 3
Section 4
然后,我可以將“杜賓犬”移動到第1節的任何位置(“香蕉”之后的除外),但是我完全不能將其移動到第3或4節。
另一方面,我可以將“ apple”和“ banana”移至第2節(“ doberman”之后除外),並且可以將其移至第3節,但不能移至第4節。
是什么賦予了? 這似乎是越野車的行為。 人們如何解決它? 蘋果知道這個錯誤嗎?
是的,這是一個蘋果蟲。 我和蘋果聊天,用我的一張“支持票”告訴他們這很不好。
我也通過從明顯的許多節表模型轉移到僅具有一個節的模型,然后將“節頭”建模為樣式化的表視圖單元來解決它。
愚蠢的蘋果...
我使用了另一個技巧:在編輯模式下用空單元格(不可見的backgroundView)創建一個虛擬的最后部分。 有了這個,我可以保持該節/行的組織,即使使用“最后一個”節,重新排序也能很好地進行。
另一種方法是使節的頁腳至少具有與單元格相同的高度。 在這種情況下,單元格可以越過最后一部分的最后一個單元格。
在此博客中,您可以了解最簡單的方法:
http://davemeehan.com/technology/moving-uitableviewcell-between-sections-in-grouped-uitableview
無論該部分是否為空。 只需在titleForFooterInSection中返回一些文本:就可以解決問題。 它甚至可以通過返回@“”來工作。
Sirdek是正確的。 只需將以下代碼復制到您的UITableViewDelegate / UITableViewDataSource中。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
NSInteger lastSection = [self numberOfSectionsInTableView:tableView] - 1;
NSInteger lastRow = [self tableView:tableView numberOfRowsInSection:lastSection] - 1;
CGFloat height = [self tableView:tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:lastRow inSection:lastSection]];
return (section == lastSection ? [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, height)] autorelease] : nil);
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
NSInteger lastSection = [self numberOfSectionsInTableView:tableView] - 1;
NSInteger lastRow = [self tableView:tableView numberOfRowsInSection:lastSection] - 1;
CGFloat height = [self tableView:tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:lastRow inSection:lastSection]];
return (section == lastSection ? height : 0);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.