Ios UITableView allows you to click a prompt, slide the delete button, and select multiple rows.

Source: Internet
Author: User

Demo function: ios UITableView enables you to click a prompt, slide to delete, and select multiple rows. Iphone 6.1 passed the test.

Demo Description: DeleteMeController. m; CheckListController. m. These are effects codes implemented using UITableView.

Demo screenshot:

Demo main code:

#import "DeleteMeController.h"     @implementation DeleteMeController  @synthesize list;  -(IBAction)toggleEdit:(id)sender {      [self.tableView setEditing:!self.tableView.editing animated:YES];     }  #pragma mark -   - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {      if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {          // Initialization code       }      return self;  }    - (void)viewDidLoad {      NSString *path = [[NSBundle mainBundle] pathForResource:@"computers" ofType:@"plist"];      NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];      self.list = array;            UIBarButtonItem *editButton = [[[UIBarButtonItem alloc]                                      initWithTitle:@"Delete"                                      style:UIBarButtonItemStyleBordered                                      target:self                                      action:@selector(toggleEdit:)] autorelease];      self.navigationItem.rightBarButtonItem = editButton;            [super viewDidLoad];  }    #pragma mark -  #pragma mark Table Data Source Methods   - (NSInteger)tableView:(UITableView *)tableView    numberOfRowsInSection:(NSInteger)section {      return [list count];  }  - (UITableViewCell *)tableView:(UITableView *)tableView            cellForRowAtIndexPath:(NSIndexPath *)indexPath {            static NSString *DeleteMeCellIdentifier = @"DeleteMeCellIdentifier";            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier];      if (cell == nil) {          cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero                                          reuseIdentifier:DeleteMeCellIdentifier] autorelease];      }      NSInteger row = [indexPath row];      cell.text = [self.list objectAtIndex:row];      return cell;  }   #pragma mark -  #pragma mark Table Delegate Methods   - (void)tableView:(UITableView *)tableView   commitEditingStyle:(UITableViewCellEditingStyle)editingStyle   forRowAtIndexPath:(NSIndexPath *)indexPath {            NSUInteger row = [indexPath row];      [self.list removeObjectAtIndex:row];      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]                        withRowAnimation:UITableViewRowAnimationFade];  }    @end  #import "DeleteMeController.h"@implementation DeleteMeController@synthesize list;-(IBAction)toggleEdit:(id)sender {[self.tableView setEditing:!self.tableView.editing animated:YES];}#pragma mark -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {// Initialization code}return self;}- (void)viewDidLoad {NSString *path = [[NSBundle mainBundle] pathForResource:@"computers" ofType:@"plist"];NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];self.list = array;UIBarButtonItem *editButton = [[[UIBarButtonItem alloc]initWithTitle:@"Delete"style:UIBarButtonItemStyleBorderedtarget:selfaction:@selector(toggleEdit:)] autorelease];self.navigationItem.rightBarButtonItem = editButton;[super viewDidLoad];}#pragma mark -#pragma mark Table Data Source Methods- (NSInteger)tableView:(UITableView *)tableView  numberOfRowsInSection:(NSInteger)section {return [list count];}- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath {static NSString *DeleteMeCellIdentifier = @"DeleteMeCellIdentifier";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier];if (cell == nil) {cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero    reuseIdentifier:DeleteMeCellIdentifier] autorelease];}NSInteger row = [indexPath row];cell.text = [self.list objectAtIndex:row];return cell;}#pragma mark -#pragma mark Table Delegate Methods- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {NSUInteger row = [indexPath row];[self.list removeObjectAtIndex:row];[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]  withRowAnimation:UITableViewRowAnimationFade];}@end

 

Related Article

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.