ios UITableView實現單擊提示,滑動刪除,多選行等操作

來源:互聯網
上載者:User

demo功能:ios UITableView實現單擊提示,滑動刪除,多選行等操作。iphone 6.1測試通過。

demo說明:DeleteMeController.m;CheckListController.m這些都是用UITableView實現的效果代碼。

demo截屏:

   

   

demo主要代碼:

#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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.