zoukankan      html  css  js  c++  java
  • 给tableView的cell上加长按转发,复制、、等功能

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        DLJobLogTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"otherCell"];
        WorkLogDataModel * model = [self.dataArray objectAtIndex:indexPath.row];
        
        [cell setup:model];
        //给cell加上长按手势
        UILongPressGestureRecognizer * longPressGesture =  [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(cellLongPress:)];
        [cell addGestureRecognizer:longPressGesture];
        [longPressGesture release];

        return cell;
    }

    #pragma mark---长按复制转发相关的一些实现方法
    // 此方法必须实现,不然会长按之后不会显示出
    - (BOOL) canPerformAction: (SEL) action withSender: (id) sender
    {
        
        if(action == @selector(handleCopyAndSendRoomCell:)||action ==@selector(handleCopyCell:))
        {
            return YES;
        }
        return NO;
        
    }
    - (void)cellLongPress:(UIGestureRecognizer *)recognizer{
        
        if (recognizer.state == UIGestureRecognizerStateBegan) {
            
            CGPoint location = [recognizer locationInView:self.tableView];
            NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
            
            WorkLogDataModel * model = (WorkLogDataModel *)[self.dataArray objectAtIndex:indexPath.row];
            NSDate * timedate = [utils dateTimeToDate:model.createDate];
            NSString * time = [self titleFromDate:timedate];
            MemberModel *member = [UtilsForUM getMemberModelWithPhone:model.phone OrWithUmid:0];
            [UIPasteboard generalPasteboard].string = [NSString stringWithFormat:@"标题:%@ 内容: %@ 转自[%@]的工作日志",time,model.msg,member.name];
            
            if (indexPath !=nil) {
                DLJobLogTableViewCell *cell = (DLJobLogTableViewCell *)recognizer.view;
                //这里把cell做为第一响应(cell默认是无法成为responder,需要重写canBecomeFirstResponder方法)
                [cell becomeFirstResponder];
                UIMenuItem *itCopy = [[UIMenuItem alloc] initWithTitle:@"转发到群组" action:@selector(handleCopyAndSendRoomCell:)];
                
                UIMenuItem *itDelete = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(handleCopyCell:)];
                
                UIMenuController *menu = [UIMenuController sharedMenuController];
                
                [menu setMenuItems:[NSArray arrayWithObjects:itCopy,itDelete,nil]];
                [menu setTargetRect:cell.frame inView:cell.superview];
                [menu setMenuVisible:YES animated:YES];
                
                [itCopy release];
                [itDelete release];
                
            }
            
        }
        
    }
    //开启长按复制转发等的响应------此方法实现在自定义的cell中
    - (BOOL)canBecomeFirstResponder{
        return YES;
    }
    -(void)handleCopyAndSendRoomCell:(id)sender
    {
        D("%@",[UIPasteboard generalPasteboard].string);
        discussionGroupController * aDGC = [[discussionGroupController alloc]init];
        aDGC.jobLogString = [UIPasteboard generalPasteboard].string;
        [utils pushViewController:aDGC animated:YES];
        [aDGC release];
    }
    -(void)handleCopyCell:(id)sender
    {
        D("%@",[UIPasteboard generalPasteboard].string);
    }

  • 相关阅读:
    MEF(Managed Extensibility Framework ) 可控扩展框架
    如何打开ASP.NET Configuration页面
    [转贴]技术的乐趣
    ORM工具介绍 NHibernate, EntitySpaces, and LLBLGen Pro 功能分析
    Linq to SQL 学习路线图
    [转贴]What is AntiPattern 什么是反模式
    Master Data Management(MDM)主数据管理
    Introducing Unity Application Block
    C#2.0 C#3.0 语言特性
    javascript声明数组三种方式
  • 原文地址:https://www.cnblogs.com/pangbin/p/5586961.html
Copyright © 2011-2022 走看看