IOS -- add the bottom toolbar and move the UITableViewCell to delete it

Source: Internet
Author: User

Add the toolbar andUITableViewCellSlide deletion

1. Add the toolbar at the bottom

When setting icons on the toolbar, you can use the built-in icons or custom icons. The following two methods are described:

1. Use the built-in icon to edit the icon)

UIBarButtonItem * editItem = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemComposetarget: selfaction: @ selector (editEventClick)];

2. Use a custom icon to delete an icon)

UIBarButtonItem * deleteItem = [[UIBarButtonItemalloc] initWithImage: [UIImageimageNamed: @ "ic_delete.png"] style: orientation: selfaction: @ selector (deleteEventClick)];

Toolbar prompt:

1. fixed space can have width ----- in all uibarbuttonitem', only UIBarButtonSystemItemFixedSpace entries can be allocated with a width. Therefore, create a space entry and set its width, add it to the entry column.

UIBarButtonItem * fixItem1 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpacetarget: nilaction: nil];

FixItem1.width = 125;

NSArray * arrayItem = [NSArrayarrayWithObjects: fixItem1, editItem, fixItem2, deleteItem, nil];

[SelfsetToolbarItems: arrayItem];

Here, the edit icon is a custom image, and the delete icon is a built-in one. You can see the difference between the two.

After running:

650) this. width = 650; "src =" http://img1.51cto.com/attachment/201307/095217487.png "title =" 1.png" style = "width: 400px; height: 52px; "width =" 400 "height =" 52 "border =" 0 "hspace =" 0 "vspace =" 0 "/>

2. Use a flexible space for left or right alignment ----- Add'UIBarButtonSystemITemFlexibleSpaceAlign all remaining entries to the right. Add one at the end to align the leftUse two uibarbuttonsystemitemflexiblespaces. Adding one at the beginning and the other at the end will align the remaining entries in the center.

UIBarButtonItem * fixItem1 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpacetarget: nilaction: nil];

NSArray * arrayItem = [NSArrayarrayWithObjects: fixItem1, deleteItem, fixItem2, editItem, fixItem2, nil];

[SelfsetToolbarItems: arrayItem];

After running:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/06401V5b-1.png "title =" 2.png" style = "width: 400px; height: 48px; "width =" 400 "height =" 48 "border =" 0 "hspace =" 0 "vspace =" 0 "/>

(Both edit and delete icons are provided by the system)

Ii. Slide Deletion

-(BOOL) tableView :( UITableView *) tableView canEditRowAtIndexPath :( NSIndexPath *) indexPath

{

ReturnYES;

}


// Define the editing Style

-(UITableViewCellEditingStyle) tableView :( UITableView *) tableVieweditingStyleForRowAtIndexPath :( NSIndexPath *) indexPath

{

ReturnUITableViewCellEditingStyleDelete;

}


// Enter the editing mode

-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyleforRowAtIndexPath :( NSIndexPath *) indexPath {

// Code

}

Enable the above two proxies and add the data deletion operation:

The effect after running is as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/06401S0T-2.png "title =" 3.png" style = "float: left; width: 200px; height: 345px; "width =" 200 "height =" 345 "border =" 0 "hspace =" 0 "vspace =" 0 "/>


















If you slide it to the left to delete it, the core code is as follows)

// Cancel the right slide of TableView and retain the left slide

UISwipeGestureRecognizer * swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: nil];

SwipeRight. direction = UISwipeGestureRecognizerDirectionRight;

[Self. tableView addGestureRecognizer: swipeRight];



This article is from the "HDDevTeam" blog, please be sure to keep this source http://hddev.blog.51cto.com/3365350/1248911

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.