Add long press forwarding, copy, and other functions to TableView's cell

Source: Internet
Author: User

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{

Dljoblogtableviewcell *cell = [TableView dequeuereusablecellwithidentifier:@ "Othercell"];
Worklogdatamodel * model = [Self.dataarray ObjectAtIndex:indexPath.row];

[Cell Setup:model];
//Add long press gesture to cell
Uilongpressgesturerecognizer * longpressgesture = [[Uilongpressgesturerecognizer alloc]initwithtarget:self action:@ Selector (celllongpress:)];
[Cell addgesturerecognizer:longpressgesture];
[Longpressgesture release];

return cell;
}

#pragma mark---Long press some implementation methods related to replication forwarding
//This method must be implemented, otherwise the president will not display after pressing
-(BOOL) Canperformaction: (SEL) Action Withsender: (ID) sender
{

if (action = = @selector (handlecopyandsendroomcell:) | | Action [email protected] (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:@ ' title:%@\n content: \n%@\n from [%@] work log ', time,model.msg , Member.name];

if (Indexpath!=nil) {
Dljoblogtableviewcell *cell = (Dljoblogtableviewcell *) Recognizer.view;
//This cell is the first response (the cell default is unable to become a responder, you need to override the Canbecomefirstresponder method)
[Cell Becomefirstresponder];
UIMenuItem *itcopy = [[UIMenuItem alloc] initwithtitle:@ "forward to group" action: @selector (Handlecopyandsendroomcell:)];

UIMenuItem *itdelete = [[UIMenuItem alloc] initwithtitle:@ "copy" 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];

}

}

}
//Turn on the response of long press replication forwarding------This method is implemented in a custom 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);
}

Add long press forwarding, copy, and other functions to TableView's cell

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.