IOS_12_tableViewCell Delete updat_dream of Red Mansions, iostableview
Finally:
Girl. h
/// Girl. h // add, delete, modify, and delete 12_tableView /// Created by beyond on 14-7-27. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <Foundation/Foundation. h> @ interface Girl: NSObject // weak is used for the UI control, and copy is used for the string. For other objects, use strong // picture name @ property (nonatomic, copy) NSString * headImgName; // name @ property (nonatomic, copy) NSString * name; // discriminant @ property (nonatomic, copy) NSString * verdict; // provides a class method, that is, constructor, returns the encapsulated Data Object (or the returned id) + (Girl *) girlNamed :( NSString *) name headImgName :( NSString *) headImgName verdict :( NSString *) verdict; // class method, the dictionary conversion object is similar to the one-time filling + (Girl *) girlWithDict :( NSDictionary *) dict; // object method. After setting the object attributes, the system returns the object-(Girl *) initWithDict :( NSDictionary *) dict; @ end
Girl. m
/// Girl. m // 12_tableView addition, deletion, modification, // Created by beyond on 14-7-27. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "Girl. h "@ implementation Girl // provides a class method, that is, the constructor, which returns the encapsulated Data Object (the returned id can also be) + (Girl *) girlNamed :( NSString *) name headImgName :( NSString *) headImgName verdict :( NSString *) verdict {Girl * girl = [[Girl alloc] init]; girl. name = name; girl. headImgName = headImgName; girl. verdict = verdict; return girl;} // class method. The dictionary conversion object is similar to a javaBean one-time filling + (Girl *) girlWithDict :( NSDictionary *) dict {// only calls the initWithDict method of the object. The reason why self is used is to be compatible with the subclass return [[self alloc] initWithDict: dict];} // object method, after setting the attributes of an object, the returned object-(Girl *) initWithDict :( NSDictionary *) dict {// call the init method of the parent NSObject if (self = [super init]) {// set the object's own property self. name = dict [@ "name"]; self. headImgName = dict [@ "headImg"]; self. verdict = dict [@ "verdict"] ;}// return the filled object return self ;}@ end
BeyondViewController. h
//// BeyondViewController. h // add, delete, modify, and delete 12_tableView /// Created by beyond on 14-7-27. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ interface BeyondViewController: UIViewController // Title @ property (weak, nonatomic) IBOutlet UILabel * titleStatus; // tableView @ property (weak, nonatomic) IBOutlet UITableView * tableView; // Clear button @ property (weak, nonatomic) IBOutlet UIBarButtonItem * trashBtn; // select all reverse button @ property (weak, nonatomic) IBOutlet initialize * checkAllBtn; // clear-(IBAction) trashBtnClick :( UIBarButtonItem *) sender; // select all or (IBAction) checkAll :( UIBarButtonItem *) sender; @ end
BeyondViewController. m
//// BeyondViewController. m // 12_tableView addition, deletion, modification, // Created by beyond on 14-7-27. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "BeyondViewController. h "# import" Girl. h "@ interface BeyondViewController () <UITableViewDataSource, UITableViewDelegate> {// all the girls loaded from the plist file, return the dictionary array NSArray * _ arrayWithDict; // all object arrays NSMutableArray * _ girls; // The model array corresponding to the selected row. // you do not need to add an attribute to the model: whether the record is selected NSMutableArray * _ checkedGirls;} @ end @ implementation BeyondViewController-(void) viewDidLoad {[super viewDidLoad]; // all object arrays _ girls = [NSMutableArray array]; // array of the selected rows _ checkedGirls = [NSMutableArray array]; // call the custom method to load the plist file [self loadPlist];} // custom method, load the plist file-(void) loadPlist {// sg_bundle template code, 1, get. MAIN package of the app; 2. Return the full path of fullPath of a file in the main package. NSBundle * mainBundle = [NSBundle mainBundle]; NSString * FullPath = [mainBundle pathForResource: @ "girls. plist "ofType: nil]; // return the dictionary array _ arrayWithDict = [NSArray arrayWithContentsOfFile: fullPath] based on the full path from the plist file; // call the custom method again, convert a dictionary array to an object array [self dictArrayToModel];} // custom method. convert a dictionary array to an object array (void) dictArrayToModel {// dictionary array _ arrayWithDict // Method 1: for in. in this case, the controller knows too much. If the model adds attributes, also change the code in the Controller/* for (NSDictionary * dict in _ arrayWithDict) {Girl * girl = [Girl girlN Amed: dict [@ "name"] headImgName: dict [@ "headImg"] verdict: dict [@ "verdict"]; [_ girls addObject: girl];} * // Method 2: The class method returns an object. You only need a dictionary array for the parameter (NSDictionary * dict in _ arrayWithDict) {// you only need a dictionary for the parameter, the controller does not need to know much. // Girl * girl = [[Girl alloc] initWithDict: dict]; Girl * girl = [Girl girlWithDict: dict]; [_ girls addObject: girl] ;}}// data source method. The default value is single group. The total number of rows (this row is called every time data is refreshed)-(NSInteger) tableView :( UITableView *) table View numberOfRowsInSection :( NSInteger) section {// return the return _ girls length of the dictionary in the array. count;} // data source method. The interface (including encapsulated data) of each row in each group should be displayed !!! Otherwise, Terminating app due to uncaught exception 'failed', reason: 'uitableview dataSource must return a cell from tableView: cellForRowAtIndexPath: '-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * cellID = @ "Beyond"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: cellID]; if (cell = Nil) {// if the pool is not obtained, a new four cell/* cell style is generated: 1, default left image right text 2, subtitle: 3 in the upper left corner, 3 in the upper left corner, and 3 in the lower right corner of the left corner, value 2 nausea left text small right text large */cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: cellID];} // set the unique content Girl * girl = _ girls [indexPath. row]; cell. textLabel. text = girl. name; cell. imageView. image = [UIImage imageNamed: girl. headImgName]; cell. detailTe XtLabel. text = girl. verdict; // judgment. if the model exists in the checkedArray, it is marked as checked if ([_ checkedGirls containsObject: girl]) {cell. accessoryType = UITableViewCellAccessoryCheckmark;} else {cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator;} // return cell;} // proxy method, height of each row-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {return 83;} // proxy method, click the row, New Version MVC-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {// clear the blue background after clicking tableView [tableView deselectRowAtIndexPath: indexPath animated: YES]; // obtain the data model Girl * girl = [_ girls objectAtIndex: indexPath. row]; // determine. If this option is not selected, select it. Otherwise, deselect the check. // Method 2: Modify only the model and move the cell to make the tableView reload data ~ If ([_ checkedGirls containsObject: girl]) {// uncheck this option, remove it from the selected array, and reloadData [_ checkedGirls removeObject: girl] Again;} else {// Add it to the selected array and reloadData again! [_ CheckedGirls addObject: girl];} // reloadData again [_ tableView reloadRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationFade]; // finally calls the custom method, check the availability of the trash button and the title change [self statusCheck];} // proxy method, click the row ---- old version-(void) oldVersionTableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {// cancel the blue color highlighted in the background after clicking tableView [tableView deselectRowAtIndexPath: indexPath animated: YES]; // obtain the clicked row UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath]; // obtain the data model Girl * girl = [_ girls objectAtIndex: indexPath. row]; // check. If it is not checked, check it. Otherwise, deselect the check. // Method 1: manually set the cell style. However, this does not conform to the MVC idea ~ /* If (cell. accessoryType! = UITableViewCellAccessoryCheckmark) {// check and add it to the array. Remember! Cell. accessoryType = UITableViewCellAccessoryCheckmark; [_ checkedGirls addObject: girl];} else {// deselect the check box and remove the cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator; [_ checkedGirls removeObject: girl];} * // Method 2: Modify the model only, do not move the cell, so that tableView reload data can be used, conforming to MVC ~ If (cell. accessoryType! = UITableViewCellAccessoryCheckmark) {// Add it to the selected array and reloadData again! [_ CheckedGirls addObject: girl]; [_ tableView reloadRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationFade];} else {// uncheck this option and remove it from the selected array, reloadData [_ checkedGirls removeObject: girl] Again; [_ tableView reloadRowsAtIndexPaths: @ [indexPath] withRowAnimation: Objects];} // Finally, call the custom method to check the trash button availability, and title change [self statusCheck];} // call-(IBAction) trashB when the trash button in the toolBar is clicked TnClick :( UIBarButtonItem *) sender {// variable array, the member is the indexPath NSMutableArray * indexPaths = [NSMutableArray array] composed of all the selected rows; // traverses checkedGirls, the selected row numbers are encapsulated into indexPath and added to the indexPaths array. The purpose is to use for (Girl * girl in _ checkedGirls) in THE tableView row deletion method) {// The row number int row = [_ girls indexOfObject: girl]; // encapsulate it into IndexPath NSIndexPath * indexPath = [NSIndexPath indexPathForRow: row inSection: 0]; // Add it to the IndexPaths array [I NdexPaths addObject: indexPath];} // modify the model first (delete the checked objects from all object arrays and clear the selected object arrays ), finally, deleteRowsAtIndexPaths (note that the number of data sources cannot be increased or decreased) [_ girls removeObjectsInArray: _ checkedGirls]; [_ checkedGirls removeAllObjects]; // After deleteRows deletes a row, the remaining number of rows must be the same as the number of rows in the data source. This means that you must delete the same number of rows in the data source before calling the deleteRows method [_ tableView deleteRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationRight]; // call the custom method to check whether the trash button can Usage, and title changes [self statusCheck];} // Finally, call the custom method to check the availability of the trash button and title changes-(void) statusCheck {// if the table has no data, disable the if (_ girls. count = 0) {_ checkAllBtn. enabled = NO;} // set to display the number of checked rows if (_ checkedGirls. count! = 0) {// if no row is selected, disable the delete button _ trashBtn. enabled = YES; // display the number (the text in bar button item cannot be changed by default, so it is changed to the label) NSString * titleStatus = [NSString stringWithFormat: @ "Dream of Red Mansions (% d) ", _ checkedGirls. count]; _ titleStatus. text = titleStatus;} else {_ trashBtn. enabled = NO; _ titleStatus. text = @ "Dream of Red Mansions" ;}// select all or reverse button on the rightmost side of the toolBar-(IBAction) checkAll :( UIBarButtonItem *) sender {if (_ girls. count = _ checkedGirls. count) {// cancel all select modify model first, then reload [_ checkedGirls removeAllObjects]; [_ tableView reloadData];} else {// select all to modify model first, reload // You must clear the checked array first, and then add [_ checkedGirls removeAllObjects]; [_ checkedGirls addObjectsFromArray: _ girls]; [_ tableView reloadData];} // call a custom method to modify the detection status [self statusCheck];} @ end
Property list file girls. plist
Main. storyboard
Because the text of bar button item cannot be changed, replace it with a label,
Label does not receive click events, so it can be passed back to the button to process click events
Is a part of version 87 deleted now? Why do I feel a part is missing each time? The more sad you are, the more likely you are to delete the plot.
I also think many of them have been deleted ~
For ios custom tableviewcell, how does one use the multiple-choice delete function provided by the system?
1. Create the TableViewCell class and inherit the parent class as UITableViewCell.
1.1
"TableCell. h"
# Import
<UIKit/UIKit. h>
/**
*
Room Table Display Structure
*
/
@ Interface
TableCell: UITableViewCell {
UILabel
* TableNoLable; // table number
UIImageView
* TableImageView; // table Image
UIImageView
* TableStateImageView; // Table Status Image
}
@ Property
(Nonatomic, retain) IBOutlet UILabel * tableNoLable; // table number
@ Property
(Nonatomic, retain) IBOutlet UIImageView * tableImageView; // table Image
@ Property
(Nonatomic, retain) IBOutlet UIImageView * tableStateImageView; // Table Status picture
1.2
TableCell.
M
# Import
"TableCell. h"
@ Implementation
TableCell
@ Synthesize
TableNoLable; // table number
@ Synthesize
TableImageView; // table Image
@ Synthesize
TableStateImageView; // Table Status picture
-
(Id) initWithStyle :( UITableViewCellStyle) style reuseIdentifier :( NSString
*) ReuseIdentifier {
If (self = [super initWithStyle: style reuseIdentifier: reuseIdentifier]) {
// Initialization code
}
Return self;
}
-
(Void) setSelected :( BOOL) selected animated :( BOOL) animated {
[Super setSelected: selected animated: animated];
// Configure the view for the selected state
}
-
(Void) dealloc {
[TableNoLable
Release];
[TableImageView
Release];
[Hand3ImageView
Release];
[Super dealloc];
}
@ End
1.3
Layout layout file (
Xib
File) specifies
Class
For your own
Tabelcellview
A new Empty Xib file, which does not contain view,
Drag a UITableCell to the two icons in libriary, double-click cellview, specify the class as the cell. m file, and start editing.
2 ...... remaining full text>