簡體   English   中英

如何將UITableViewCell放到UITableView的底部。

[英]How to drop UITableViewCell to bottom of UITableView.

一個UITableView有20行的UITableViewCell,每行上確實有一個按鈕,單擊按鈕,我想將UITableViewCell放到UITableView的底部。

是否有任何委托方法可以做到這一點。 您的反饋將不勝感激。

是的,在tableview上有一個方法

- (void)moveRowAtIndexPath:(NSIndexPath*)indexPath
               toIndexPath:(NSIndexPath*)newIndexPath

您可以閱讀更多https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/moveRowAtIndexPath:toIndexPath

是的,只有一個!

為此,請使用以下委托方法:

必須返回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文檔以獲取相同信息:

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/ManageReorderRow/ManageReorderRow.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM