Tangle implementation of multiple-choice deletion based on tabBar similar to mail

Source: Internet
Author: User

In this case, multiple options of tableview deletion are justified. In tabbar, it is no error to delete multiple options of tableview. If you want to use tableview multiple-choice deletion in the tabbar, you need to achieve the same effect as the system's built-in mail multiple-choice deletion. Well, since the product is designed in this way and reasonable or unreasonable is one thing, whether or not it can be realized is my business, holding the belief that "as long as it can be realized, I can achieve it ", after seven or eight hours of struggle, we finally achieved this inconspicuous little effect.

Start Interface

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/132P31643-0.png "/>

Click Edit.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/132P31593-1.png "/>

Select the row to be deleted

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/132P31R9-2.png "/>

Point: effect after deletion

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/132P3A93-3.png "/>

Effect after point clearing

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/132P35304-4.png "/>

Click to determine the effect

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/132P31462-5.png "/>

In addition to multiple tabbar selections, the core code adds a hidden tabbar, two deletion buttons and related processing methods to the toolbar.

 
 
  1. -(Void) hideTabBar :( BOOL) hidden {
  2. [UIView beginAnimations: nil context: NULL];
  3. [UIView setAnimationDuration: 0];
  4. For (UIView * view in self. tabBarController. view. subviews)
  5. {
  6. If ([view isKindOfClass: [UITabBar class])
  7. {
  8. If (hidden ){
  9. [View setFrame: CGRectMake (view. frame. origin. x, 480, view. frame. size. width, view. frame. size. height)];
  10. } Else {
  11. [View setFrame: CGRectMake (view. frame. origin. x, 480-49, view. frame. size. width, view. frame. size. height)];
  12. }
  13. }
  14. Else
  15. {
  16. If (hidden ){
  17. [View setFrame: CGRectMake (view. frame. origin. x, view. frame. origin. y, view. frame. size. width, 480)];
  18. } Else {
  19. [View setFrame: CGRectMake (view. frame. origin. x, view. frame. origin. y, view. frame. size. width, 480-49)];
  20. }
  21. }
  22. }
  23. [UIView commitAnimations];
  24. }
  25. -(Void) buttonClicked :( id) sender {
  26. Switch ([sender tag]) {
  27. Case 1:
  28. // NSLog (@ "");
  29. [DataArray removeObjectsInArray: [deleteDic allKeys];
  30. [Self. tableView deleteRowsAtIndexPaths: [NSArray arrayWithArray: [deleteDic allValues] withRowAnimation: UITableViewRowAnimationFade];
  31. [DeleteDic removeAllObjects];
  32. Break;
  33. Case 2:
  34. // NSLog (@ "");
  35. ; NSMutableArray * tmpArray = [[NSMutableArray alloc] init];
  36. Int end = [dataArray count];
  37. For (int I = 0; I <end; I ++ ){
  38. [TmpArray addObject: [NSIndexPath indexPathForRow: I inSection: 0];
  39. }
  40. [DataArray removeAllObjects];
  41. [Self. tableView deleteRowsAtIndexPaths: [NSArray arrayWithArray: tmpArray] withRowAnimation: UITableViewRowAnimationFade];
  42. [TmpArray release];
  43. Break;
  44. Default:
  45. Break;
  46. }
  47. }
  48. -(Void) clearAllHistory {
  49. If (self. navigationItem. rightBarButtonItem. title = @ "edit "){
  50. // Hide the tabbar
  51. [Self hideTabBar: YES];
  52. // Display toolbar
  53. Self. navigationController. toolbar. barStyle = UIBarStyleBlack;
  54. Self. navigationController. toolbarHidden = NO;
  55.  
  56. If (selectBtn = nil ){
  57. UIButton * myBtn1 = [UIButton buttonWithType: UIBarButtonItemStylePlain];
  58. SelectBtn = myBtn1;
  59. MyBtn1.frame = CGRectMake (0.0f, 0.0f, 80366f, 30366f );
  60. [MyBtn1 setTitle: @ "Delete (0)" forState: UIControlStateNormal];
  61. [MyBtn1 setTag: 1];
  62. [MyBtn1 setBackgroundImage: [UIImage imageNamed: @ "bbg.png"] forState: UIControlStateNormal];
  63. [MyBtn1 addTarget: self action: @ selector (buttonClicked :) forControlEvents: UIControlEventTouchUpInside];
  64. DeleteBtn = [[UIBarButtonItem alloc] initWithCustomView: myBtn1];
  65. UIButton * myBtn2 = [UIButton buttonWithType: UIBarButtonItemStylePlain];
  66. MyBtn2.frame = CGRectMake (0.0f, 0.0f, 80366f, 30366f );
  67. [MyBtn2 setTitle: @ "clear" forState: UIControlStateNormal];
  68. [MyBtn2 setTag: 2];
  69. [MyBtn2 setBackgroundImage: [UIImage imageNamed: @ "bbg.png"] forState: UIControlStateNormal];
  70. [MyBtn2 addTarget: self action: @ selector (buttonClicked :) forControlEvents: UIControlEventTouchUpInside];
  71. ClearBtn = [[UIBarButtonItem alloc] initWithCustomView: myBtn2];
  72. SpaceBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil];
  73. }
  74. [Self. navigationController. toolbar setItems: [NSArray arrayWithObjects: spaceBtn, spaceBtn, deleteBtn, clearBtn, spaceBtn, spaceBtn, nil] animated: YES];
  75. Self. navigationItem. rightBarButtonItem. title = @ "OK ";
  76. [Self. tableView setEditing: YES animated: YES];
  77. }
  78. Else {
  79. Self. navigationItem. rightBarButtonItem. title = @ "edit ";
  80. Self. navigationController. toolbarHidden = YES;
  81. [Self hideTabBar: NO];
  82. [DeleteDic removeAllObjects];
  83. [Self. tableView setEditing: NO animated: YES];
  84. }
  85. }
There are three difficulties in implementing the entire effect: 1. Hiding tabbar. As a controller, it does not allow itself to be hidden. Finally, the toolbar method is hidden using the method provided by laigb of cocochina. Http://www.cocoachina.com/bbs/read.php? Tid = 25042 & page = 3 #206318. However, the value of y used by laigb is 320. It should be used by devices before iPhone 4. 2. The buttons added by default to the relatively center toolbar of the two delete buttons are arranged from the left to the right. If you add two items, the system runs to the far left by default. Therefore, placeholders must be used in this area. 3. modify the tag: "Delete (0)" there are two tangle points in this place. 1) Save the reference of this button for easy modification; 2) when you modify its value, you must select "Delete (0)" as the placeholder, otherwise it will be changed to "Delete (1)" later, and the display will not be complete.

 

This article is from the "rainbird" blog, please be sure to keep this source http://rainbird.blog.51cto.com/211214/645772

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.