Create Operations/delete UITableView details for multiple rows of data
Source: Internet
Author: User
First note the need to rewrite-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (Nsindexpath *) Indexpath It is important to note that the returned result should be return Uitableviewcelleditingstyledelete | Uitableviewcelleditingstyleinsert; Although this in the xcode4.2 compiler may be error, hint type problem, self do a strong turn can, of course, if your program has been completely eliminated iOS4, using ios5 words, in fact, TableView has a special variable to set, that is, the allowsmultipleselection variable is set to Y Es. Using the style above tells TableView that we need to do a multiline operation. Then when we need to go into multi-line operations, we definitely need to go into edit mode, so we need to call [Self.tableview Setediting:yes Animated:yes] After entering edit mode, click cell to select and reverse, this time we need to record those cells are selected, those cells are not selected, that is, in the following methods to deal with -(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath -(void) TableView: (UITableView *) TableView Didderowatindexpath: (Nsindexpath *) Indexpath This allows us to record the array of cells that need to be manipulated. If you just need a general tableview for a multiline operation, then basically it's almost done. But if your interface is a bit of a style, you may need to do more. Because by default, the left circle and the checkmark are the system defaults, and there seems to be no place to modify them. Besides, you're also prone to problems with the style of some of the map colors in the cell because the left side shrinks. Then my own solution is below. The first thing to look at is the UITableViewCell Selectionstyle, the style has 3 values, respectively: Uitableviewcellselectionstylenone Uitableviewcellselectionstyleblue UitableviewcellselectionstylegrayAs the name implies, the color that appears when the cell is selected, but there is a seemingly magical place. is when you set the cell to Uitableviewcellselectionstylegray or uitableviewcellselectionstyleblue, and when you enter multi-select edit mode, The cell you selected will have a white check bar, and it seems very difficult to modify its color, then when your cell actual background color and this partial white check bar is not harmonious, I think it is your headache. So in order to be able to choose the editing situation can fully customize the selected effect, My practice is when the TableView editing for Yes when set Cell.selectionstyle to Uitableviewcellselectionstylenone, so whether we choose not to select the cell, the system will not actively help me do some self-thought good effect. But at the same time, because of the removal of the selected effect, in order to express which cells we selected, we need to rewrite the cell's Select method to self-plot the response selection effect. That is, rewrite the Select method in your custom cell class[Plain]View Plaincopy-(void) setselected: (BOOL) selected animated: (bool) Animated {if (self.editing)//You need to handle only when editing the state Check effect {if (selected) {//effect checked)} else {//unchecked When the effect}}}
This solves the effect of selecting and not selecting. But there is another problem, that is, in the multi-select state of the left side of the circle and the check is still not ready, my approach is: rewrite the cell's Edit method
[Plain] View Plaincopy-(void) setediting: (BOOL) editing animated: (bool) animated { if (editing)//Edit Status { if (self.editingstyle == (uitableviewcelleditingstyleinsert| Uitableviewcelleditingstyledelete) { //Edit multiple selection status if (![ Self viewwithtag:tagvale]) //Edit Multi-select state to add a custom picture to replace the original system default circle, note that this picture is selected and unchecked when the attention to switch pictures to simulate the effect of the system { uiimage* img = [uiimage imagenamed:@ "Dot.png"]; uiimageview* editdotview = [[uiimageview alloc] initwithimage:img]; editDotView.tag = TagVale; editDotView.frame = CGRectMake (10,15,20,20); [self addSubView:editDotView]; [editdotview release],editdotview = nil; } } } else { //Non-edit mode to check if there are dot pictures, some words delete UIView* editDotView = [self viewWithTag:TagValue]; if (editdotview) { [editDotView removeFromSuperview]; } } }
Note Here we need to adjust the location of the dot picture itself, because I this cell is 50 height, so write, in summary, when you need to customize a multi-select editing state and do not need to fully customize a control, many modified under TableView some properties, Multi-combination rewrite cell select,edit,highlight and other methods can obtain the corresponding effect. This is it.
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.