UITableView具有20行的UITableViewCell,每行都有一個按鈕,單擊按鈕我想將UITableViewCell放到底部到UITableView。如何將UITableViewCell拖放到UITableView的底部。
是否有任何委託方法爲它做。 您的反饋將不勝感激。
UITableView具有20行的UITableViewCell,每行都有一個按鈕,單擊按鈕我想將UITableViewCell放到底部到UITableView。如何將UITableViewCell拖放到UITableView的底部。
是否有任何委託方法爲它做。 您的反饋將不勝感激。
是的,有上實現代碼如下
- (void)moveRowAtIndexPath:(NSIndexPath*)indexPath
toIndexPath:(NSIndexPath*)newIndexPath
是的,有一個!
使用下面的委託方法爲:
必須返回YES
允許的tableView行的canMoveRowAtIndexPath
委託方法移動按照您的要求,
- (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
}
Like 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]];
}
另請閱讀同蘋果文檔:
可以u顯示UR與按鈕操作碼 –