自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開(kāi)發(fā)應(yīng)用中NSTableView相關(guān)操作

移動(dòng)開(kāi)發(fā) iOS
iPhone開(kāi)發(fā)應(yīng)用中NSTableView相關(guān)操作是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)NSTableView的使用方法,如何使NSTableView同時(shí)支持拖拽替換和拖拽插入。

iPhone開(kāi)發(fā)應(yīng)用中NSTableView相關(guān)操作是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)NSTableView的使用方法,如何使NSTableView同時(shí)支持拖拽替換和拖拽插入。

當(dāng)你的NSTableView做為一個(gè)拖拽目標(biāo)時(shí),你可能希望同時(shí)支持拖拽替換當(dāng)前項(xiàng)目,或者拖拽后在當(dāng)前位置插入新的項(xiàng)目。你需要使用NSTableView的 -setDropRow:dropOperation:方法。本文介紹如何通過(guò)代碼實(shí)現(xiàn)NSTableView的這種拖拽功能。

代碼如下所示:

  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);  

同時(shí),在acceptDrop方法里進(jìn)行如下操作:

  1. - (BOOL) tableView: (NSTableView *) view  
  2.         acceptDrop: (id ) info  
  3.                row: (int) row  
  4.      dropOperation: (NSTableViewDropOperation) op  
  5. {  
  6.     if (op == NSTableViewDropOn) {  
  7.         // 替換  
  8.     } else if (op == NSTableViewDropAbove) {  
  9.         // 插入  
  10.     } else {  
  11.         NSLog (@"unexpected operation (%d) in %s",  
  12.                op, __FUNCTION__);  
  13.     }  
  14.     return (YES);  

在NSTableView選擇項(xiàng)改變時(shí)獲取通知

代碼如下所示:

  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. }  

這段代碼需要放在NSTableView的delegate里。如果沒(méi)有delegate,可以將自身設(shè)置為delegate。

小結(jié):iPhone開(kāi)發(fā)應(yīng)用中NSTableView相關(guān)操作的內(nèi)容介紹完了,希望通過(guò)本文的學(xué)習(xí)能對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: cocoachina
相關(guān)推薦

2011-08-19 13:34:33

iPhone應(yīng)用ABAddressBo

2011-08-17 10:24:50

iPhone開(kāi)發(fā)UIImage圖片

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-15 11:37:20

iPhone開(kāi)發(fā)Mask

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-12 14:33:06

iPhone緩存文件

2011-08-15 15:44:46

iPhone開(kāi)發(fā)PDF

2011-08-18 16:24:44

iPhone開(kāi)發(fā)圖片

2012-04-26 13:45:20

iPhone應(yīng)用發(fā)布稅務(wù)相關(guān)手續(xù)

2012-04-26 13:26:58

iPhone應(yīng)用技巧

2011-08-03 16:01:24

iPhone應(yīng)用開(kāi)發(fā) 自動(dòng)登陸

2011-08-12 13:30:27

iPhoneASIFormData架構(gòu)

2011-08-11 15:23:04

iPhoneNSBundleXcode

2011-08-08 13:50:29

iPhone開(kāi)發(fā) NSOperatio 多線程

2011-08-15 13:44:07

iPhone開(kāi)發(fā)UITableView

2011-08-12 09:48:24

iPhoneCoreLocatio定位

2011-08-16 15:48:37

iPhone開(kāi)發(fā)抓圖程序

2011-07-26 11:13:15

iPhone PXL

2011-07-19 09:46:38

2011-07-08 14:58:16

iPhone Xcode iOS
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)