iphone - Checkbox image toggle in UITableViewCell -


I need some guidance in order to create a UITableViewCell that has an image on the left that can be toggled. The image should work as tappable and toggle (checkbox).

I am struggling with my part:

  1. How do I know the taps on the image and handle them differently? SelectEndexpath?
  2. How do I change the image without executing [TableView reloadData]?

See the image below for a sample:

thanks

This is really very easy.

Just create a new subclass of UIControl and put it there (no need for a different controller.) Let's call it toggleimage control.

  @interface toggleimage control: UIC control {BOOL selected; UIImageView * imageView; UIImage * Normal Image; UIImage * selectedImage; }  

Create a toggleimage control for each cell, and add it to the proper position.

  Toggle image control * Toggle dialog = [[ToggleMinroll alloc] initWithFrame: & lt; Frame & gt;] ToggleControl.tag = indexPath.row; // [Cell.contentView addSubview: toggleControl] for reference in the notification;  

Add a UIImageView to include the picture Add a target for the touch event.

  - (zero) viewDidload {normal image = [UIImage imageNamed: @ "normal.png"]; SelectedImage = [UIImage imageNamed: @ "selected.png"]; ImageView = [[UIImageView alloc] initWithImage: normal image]; // set image view frame [self.view addSubview: imageView]; [Self addTarget: Self-action: @Selector (toggle image) for control events: UIControlEventTouchUpInside]; }  

set UIImageView's image property to update the image; Which will trigger the red color without side effects.

  - (zero) toggle image {selected =! Selected; ImageView.image = (Selected? Selected Image: General Image); // Use NSNotification or other method to inform the data model about state change // Notification example: NSDRIZATION * Dictry = [NSDD dictionary with object: [NSNumber Number: STT FORK: @ "cell check Toggle"] ; [[NSNotificationCenter defaultCenter] postNotificationName: @ "cell checkoglad" object: self user information: dict]; }  

You must clearly massage some things. You probably want to pass it in two image names to make it more reusable, as well as I recommend specifying the notification name string from the outside of the object (assuming that you are using the notification method ).


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -