UITableViewCell with 2 helper types

I would like to do UITableViewCellwith one tag and two types of accessories:

  • Unselected cells should display an accessory UITableViewCellAccessoryDetailDisclosureButton.
  • The selected cell should display accessories UITableViewCellAccessoryDisclosureIndicatorand UITableViewCellAccessoryDetailDisclosureButton.

The only way I know how to do this is to use the image for the selected kind of accessories. Is there an alternative way to do this?

+3
source share
2 answers

AT

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    selectedIndex = indexPath //selectedIndex is a property

}

Then in

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//usual cell stuff

    if(indexPath == selectedIndex) 
        [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    else
        [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];


}

So, the trick is to save the link to the selected cell and set the indicator accordingly.

, , selectedIndex, selectIndex = nil.

+1

UITableViewCell ( , ).

+2

All Articles