IOS implementation Click to use 3D Touch in TableView

Source: Internet
Author: User



So ugly.
Test the phone iphone6s, that is, using the new feature 3DTouch. I don't know how hard I think it will be.

Before you start

// 签订这个协议
-(uitableviewcell  *) TableView: (uitableview  *) TableView Cellforrowatindexpath: ( nsindexpath  *) indexpath{uitableviewcell  *    cell = [TableView dequeuereusablecellwithidentifier:@ "Cellid" ];    //specifies the proxy for each cell, which is roughly the meaning of  [self  registerforpreviewingwithdelegate:self     Sourceview:cell]; // cell.textlabel  .text  = self   [Indexpath.row ]; return  Cell;}  
#pragma mark-peek proxy method, tap to trigger pop-up VC- (Uiviewcontroller*) Previewingcontext: (ID<UIViewControllerPreviewing>) Previewingcontext viewcontrollerforlocation: (Cgpoint) location{//through [Previewingcontext Sourceview] to get the corresponding cell data;    Nsindexpath*indexpath = [_tableview Indexpathforcell: (UITableViewCell*) [Previewingcontext Sourceview]];//VC for displaying previewsListviewcontroller *LISTVC = [[Listviewcontroller alloc] init];//demo is to pass in a string that may actually be the model you needListvc. StrText= [ Self. ArraydataObjectatindex:indexpath. Row];returnLISTVC;}#pragma mark-pop proxy method, where you can process the VC that will be entered- (void) Previewingcontext: (ID<UIViewControllerPreviewing>) Previewingcontext Commitviewcontroller: (Uiviewcontroller*) viewcontrollertocommit{}

In Listviewcontroller I use a label as a demo, you may also need to add a bottom menu (similar to favorites like this)

-(Nsarray<ID<UIPreviewActionItem>> *) Previewactionitems {uipreviewaction * action1 = [Uipreviewaction actionwithtitle:@"Favorites"Style1handler:^ (uipreviewaction * _nonnull action,Uiviewcontroller* _nonnull Previewviewcontroller) {NSLog(@"Favorites");     }]; Uipreviewaction * Action2 = [Uipreviewaction actionwithtitle:@"Loved it"Style0handler:^ (uipreviewaction * _nonnull action,Uiviewcontroller* _nonnull Previewviewcontroller) {NSLog(@"Loved it"); }];Nsarray*items = @[action1,action2];returnItems;}

IOS implementation Click to use 3D Touch in TableView

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.