2

I have an application with a table view with checkmark buttons.Using the subclassing of UIcontroll.using this

How to display a Subclass of UIControl on the screen it will simply toggle the images.In my case i have two sections.when i select the button on the section 0 it will have to deselect all the other buttons selected.For that button only,and also i need to know whichever buttons is selected by the user.Can anybody help me?

Community
  • 1
  • 1
angry_developer
  • 215
  • 1
  • 11
  • Provide some code, and I'll help you. Add a method in your ToggleImageControl which sets some property each time a user toggles the picture. You already have the method toggleImage. – Martol1ni Oct 31 '12 at 08:35
  • the code is same as that in the link.everything is there. – angry_developer Oct 31 '12 at 08:44

1 Answers1

0

The easiest way to communicate among ui elements is to publish an event. So in this case what you want is to capture the touch event or checkbox change event, then publish an event that your button is selected. In the other cells, listen for the event and when another checkbox is selected, the cell sets it's checkbox to deselected.

In the selecting cell:

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:checkbox forKey:@"selectedCheckbox"];
   [[NSNotificationCenter defaultCenter] postNotificationName:@"checkboxSelected" object:nil userInfo: userInfo];               

In the other cells:

   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearSelection) name:@"checkboxSelected:" object:userInfo];
... look in the 
-(void) checkboxSelected: (NSNotification *) note  {
    NSDictionary * userInfo = note.userInfo;
    checkbox = (UnMessage *)[userInfo objectForKey:@"selectedCheckbox"];
    if(checkbox == myCheckbox) return; // ignore
// deselect my checkbox...

and on dealloc on the cell:

 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"checkboxSelected" object:nil];