NSTableView operations in iPhone development applications

Source: Internet
Author: User

IPhone DevelopmentApplication in progressNSTableViewRelevant operations are described in this article, mainly to learnNSTableViewHow to UseNSTableViewDrag/drop replacement and insert are also supported.

When yourNSTableViewAs a drag-and-drop target, you may wish to support both drag-and-drop replacement of the current project, or drag and drop to insert a new project in the current position. You need to use NSTableView's-setDropRow: dropOperation: method. This article describes how to implement the drag-and-drop function of NSTableView through code.

The Code is as follows:

 
 
  1. - (NSDragOperation) tableView: (NSTableView *) view  
  2.                  validateDrop: (id ) info  
  3.                   proposedRow: (int) row  
  4.         proposedDropOperation: (NSTableViewDropOperation) op  
  5. {  
  6.     [view setDropRow: row  
  7.                dropOperation: op];  
  8.     NSDragOperation dragOp = NSDragOperationCopy;  
  9.     return (dragOp);  

In addition, perform the following operations in the acceptDrop method:

 
 
  1. -(BOOL) tableView: (NSTableView *) view
  2. AcceptDrop: (id) info
  3. Row: (int) row
  4. DropOperation: (NSTableViewDropOperation) op
  5. {
  6. If (op = NSTableViewDropOn ){
  7. // Replace
  8. } Else if (op = nstableviewdropabve ){
  9. // Insert
  10. } Else {
  11. NSLog (@ "unexpected operation (% d) in % s ",
  12. Op, _ FUNCTION __);
  13. }
  14. Return (YES );
  15. }

Get a notification when the NSTableView option is changed

The Code is as follows:

 
 
  1. - (void) tableViewSelectionDidChange: (NSNotification *) notification  
  2. {  
  3.     int row;  
  4.     row = [tableView selectedRow];  
  5.               
  6.     if (row == -1) {  
  7.         //do stuff for the no-rows-selected case  
  8.     }   
  9.       
  10.     else {  
  11.        // do stuff for the selected row  
  12.     }  
  13. }  

This code should be placed in the delegate of NSTableView. If no delegate exists, you can set it to delegate.

Summary:IPhone DevelopmentApplication in progressNSTableViewThe related operations have been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.