2011-09-05 234 views
1

任何人都可以請我提供一個表視圖樣本拖動&拖放功能?TableView拖放功能

+0

可能的重複http://stackoverflow.com/questions/3481858/tutorial-on-how-to-drag-and-drop-item-from-uitableview-到的UITableView – jussi

回答

4

當您創建的UITableView控制器的一個子類,取消以下方法(或只是添加它們如果要實現自定義類UITableViewdelegatedataSource協議):

// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
    // update your model 
} 

// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the item to be re-orderable. 
    return YES; 
} 

現在你只需要編輯按鈕開始編輯模式(你可以把它放在viewDidLoad中):

self.navigationItem.rightBarButtonItem = self.editButtonItem; 

tableView:moveRowAtIndexPath:toIndexPath:方法裏面,你應該通過重新排列陣列更新模型或任何持有你數據。

1

是你需要重新排列嗎? 。如果是這樣檢查this或者如果您需要拖放檢查this