Ios-uitableviewcell change Edit Status picture

Source: Internet
Author: User
Tags uicontrol

UITableViewCell is the editing state will appear when the multiple-selection button, the recent project has the need to change to their own pictures and remove the Click Effect, summed up: The effect of the picture is like this:




The effect we need is to replace the blue selected picture and click on the background color effect is probably like this:



we come in one step:


First, replace the blue selected pictures with their own: The method is to first traverse the cell Contentview to get this picture and then replace, found in the custom cell-(void) setselected: (BOOL) selected animated: (bool Animated method specific code: (void) setselected: (BOOL) selected animated: (BOOL) animated
{
if (!self.editing) return;
[Super setselected:selected animated:animated];
if (self.isediting && self.isselected) {

  Self.contentView.backgroundColor     = [Uicolor clearcolor];
  This customizes the cell to change the color of the custom control
  self.textLabel.backgroundColor       = [Uicolor clearcolor];
  Uicontrol *control = [Self.subviews lastobject];
  Uiimageview * Imgview = [[Control subviews] objectatindex:0];
  Imgview.image = [UIImage imagenamed:@ "picture to replace"];
}
} The effect is this when you add this code:


can see the picture is already changed, but the effect of the click is not removed, next remove the effect of the click, we can according to the cell Selectedbackgroundview properties to change, specific code:


(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier
{
self = [super Initwithstyle:style reuseidentifier:reuseidentifier];
if (self)
{

   Self.contentView.backgroundColor = [Uicolor clearcolor];
   UIView *backgroundview = [[UIView alloc]init];
   Backgroundview.backgroundcolor = [Uicolor clearcolor];
   Self.selectedbackgroundview = Backgroundview;
   The following custom controls
}
return self;
} The effect is as follows:


This is basically good, but sometimes the blue icon of the system will also come out, found that the problem is highlighted, all in the cell inside also want to implement this method:

-(void) sethighlighted: (BOOL) highlighted animated: (BOOL) animated{

    [Super sethighlighted:highlighted animated:animated];    if (self.isediting && self.ishighlighted) {
 //        Uicontrol *control = [Self.subviews lastobject];
 //        Uiimageview * Imgview = [[Control subviews] objectatindex:0];        imgview.image = [uiimage imagenamed:@ "dc_agree_selected"];    } return
 ;

inside the highlight state of the picture into their own can be, I tried direct return can also.


Follow-up: To implement UITableView before editing, enter the edit state first:

 -(BOOL) TableView: (UITableView *) TableView Caneditrowatindexpath: (Nsindexpath *) Indexpath {return YES; }-(Uitableviewcelleditingstyle) TableView: (UITableView *) TableView Editingstyleforrowatindexpath: (NSIndexPath *) Indexpath {return Uitableviewcelleditingstyledelete |
 Uitableviewcelleditingstyleinsert; }-(void) TableView: (UITableView *) TableView Commiteditingstyle: (uitableviewcelleditingstyle) Editingstyle Forrowatindexpath: (Nsindexpath *) Indexpath {if (Editingstyle = = (uitableviewcelleditingstyledelete| 
         Uitableviewcelleditingstyleinsert)) {[Self.datasoure removeobject:[self.datasoure ObjectAtIndex:indexPath.row]]; There are several ways to delete the animation [TableView Deleterowsatindexpaths:@[indexpath] Withrowanimation:uitableviewrowan
     Imationfade]; }
 }
How do I handle checked and unchecked data? Using the system's own method, we can first define a variable array @property (Nonatomic,strong) nsmutablearray* Selectarray; The Didselectrowatindexpath and Diddeselectrowatindexpath methods are then found in the TableView protocol method, which is implemented in detail:
#pragma mark-uitableviewdelegate

 -(void) TableView: (UITableView *) TableView Didselectrowatindexpath: ( Nsindexpath *) Indexpath
 {
     [Self.selectarray addobject:[self.datasoure ObjectAtIndex:indexPath.row]];
 }

 -(void) TableView: (UITableView *) TableView Diddeselectrowatindexpath: (Nsindexpath *) Indexpath
 {
     [ Self.selectarray removeobject:[self.datasoure ObjectAtIndex:indexPath.row]];
 }
<br/>
study and progress together Wen/Dong Fei
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.