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

iOS5上的UITableView新API

移動開發(fā) iOS
今天看到UITableView關(guān)于iOS5新增的API,有三個關(guān)于將UIMenuViewController使用到UITableViewCell上,以前還為讓Cell實現(xiàn)這個功能糾結(jié)過,哈哈,一起看看·
  1. - (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath  
  2. {  
  3.     return YES;  
  4. }  
  5. - (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender   
  6. {  
  7.     return  YES;  
  8. }  
  9. - (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender  
  10. {  
  11.     if (action == @selector(copy:)) {  
  12.         [UIPasteboard generalPasteboard].string = [dataArray objectAtIndex:indexPath.row];  
  13.     }  
  14.     if (action == @selector(cut:)) {  
  15.          [UIPasteboard generalPasteboard].string = [dataArray objectAtIndex:indexPath.row];  
  16.         [dataArray replaceObjectAtIndex:indexPath.row withObject:@""];  
  17.         [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];  
  18.     }  
  19.     if (action == @selector(paste:)) {  
  20.         NSString *pasteString = [UIPasteboard generalPasteboard].string;  
  21.         NSString *tmpString = [NSString stringWithFormat:@"%@%@",[dataArray objectAtIndex:indexPath.row],pasteString];  
  22.         [dataArray replaceObjectAtIndex:indexPath.row withObject:tmpString];  
  23.         [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];  
  24.     }  

如果希望只出現(xiàn)一個或兩個特定的菜單選項,可以在- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender 中加入相應(yīng)判斷,return YES則出現(xiàn),return NO則不出現(xiàn)了。

第三個函數(shù)就是我們處理邏輯的地方,我這里只是測試簡單純文本Cell。

這樣長按就可以出現(xiàn)三個功能菜單選項,點擊進行相應(yīng)操作。

【編輯推薦】

  1. ios5中UIViewController新使用方法
  2. iOS應(yīng)用開發(fā)新手教程:iOS5 UIKit新特性
  3. 蘋果iOS5.1安全漏洞,設(shè)備可由5.1降級5.0.1?
責(zé)任編輯:冰凝兒 來源: DEVDIV博客
相關(guān)推薦

2012-01-18 14:14:29

iOS教程iOS5

2012-01-18 13:51:39

2012-12-24 14:53:44

ios

2011-09-19 15:42:33

TwitteriOS5

2013-03-25 13:41:10

iOS5ARC內(nèi)存管理

2011-08-09 14:25:43

蘋果iCloudiOS5

2012-05-27 20:21:40

2011-10-05 01:51:20

iOS5蘋果

2011-06-08 10:29:37

開源閉源蘋果

2011-05-31 22:53:14

喬布斯WWDCiCloud

2011-07-07 16:38:21

iOS UITableVie

2013-06-20 11:21:58

iOS開發(fā)UITableView

2011-06-07 06:59:51

iOS 5iOS蘋果

2013-12-12 10:46:22

2011-10-19 16:19:27

iOS 5蘋果

2011-06-09 10:51:53

iPhone 3GSiOS5蘋果

2013-07-22 14:47:56

iOS開發(fā)iOS5中ASIHtt

2011-06-07 07:06:33

iOS 5iOSWWDC

2011-06-15 09:53:42

2011-11-01 16:50:25

iOS5蘋果中國用戶
點贊
收藏

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