2016-07-28 59 views

回答

1

是的,有一個!

使用下面的委託方法爲:

必須返回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]]; 

} 

另請閱讀同蘋果文檔:

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

相關問題