![](/img/trans.png)
[英]Pan gesture in UITableViewCell prevents scrolling in UITableView. How to fix it?
[英]How to drop UITableViewCell to bottom of UITableView.
一個UITableView有20行的UITableViewCell,每行上確實有一個按鈕,單擊按鈕,我想將UITableViewCell放到UITableView的底部。
是否有任何委托方法可以做到這一點。 您的反饋將不勝感激。
是的,在tableview上有一個方法
- (void)moveRowAtIndexPath:(NSIndexPath*)indexPath
toIndexPath:(NSIndexPath*)newIndexPath
是的,只有一個!
為此,請使用以下委托方法:
必須返回YES
以允許根據您的要求在canMoveRowAtIndexPath
委托方法中移動tableView行,
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) // Don't move the first row
return NO;
return YES;
}
然后,使用moveRowAtIndexPath
委托方法相應地為重定位的行更新數據模型數組,
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
//Updating the data-model array
}
就像單擊按鈕中的moveRowAtIndexPath
一樣,
- (void)btnClick:(UIButton*)sender
{
UITableViewCell *cell = (UITableViewCell *)sender.superview;
NSIndexPath *indexpath = [tableView indexPathForCell:cell];
//Change accordindly as per requirement
[tableView moveRowAtIndexPath:[NSIndexPath indexPathForItem:indexpath.row inSection:indexpath.section] toIndexPath:[NSIndexPath indexPathForItem:0 inSection:indexpath.section]];
}
另外,請閱讀Apple文檔以獲取相同信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.