开发者

TableView drag & drop functionality

Can anyone please provid开发者_如何学编程e me a sample for table view drag & drop functionality?


When you create a subclass of UITableView controller, uncomment the following methods (or just add them if you are implementing UITableView delegate and dataSource protocols in custom class):

// 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;
}

Now you just need an edit button to start editing mode (you can put it in viewDidLoad):

self.navigationItem.rightBarButtonItem = self.editButtonItem;

And inside that tableView:moveRowAtIndexPath:toIndexPath: method you should update your model by rearranging array or whatever is holding your data.


is that you need to rearrange ? . If so check this or if you need drag drop check this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜