Kuldeep Singh
Kuldeep Singh

Reputation: 1284

A table that allows some cells to be checkmarked..?

i am new to iphone development.. i am making an application in which table view list the names of countries... user has to select one or more countries at a time..i want to display the checkmark disclosure button at the entries that are selected..how can i do that..

and another thing..i want to deselect the entry when user again clicks on the same name..means the checkmark will be removed..

Upvotes: 0

Views: 111

Answers (2)

karim
karim

Reputation: 15589

in the method,

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
            (NSIndexPath *)indexPath {
            // You have an array of countries and track all indexes that are selected.
            // If the indexing is synced with the cell index, then 
            UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
            if (/* this index's country is selected */)
                cell.accessoryType = UITableViewCellAccessoryNone;
            else {
                // update this index's country to selected state.
                cell.accessoryType = UITableViewCellAccessoryCheckmark;
            // you can keep an array of indexes, which cells/country is selected and store the status of selection in the array for further use.
            }
        }

Upvotes: 0

taskinoor
taskinoor

Reputation: 46037

To show the checkmark:

cell.accessoryType = UITableViewCellAccessoryCheckmark

To clear the checkmark:

cell.accessoryType = UITableViewCellAccessoryNone

You can toggle this easily by testing the current value.

Upvotes: 1

Related Questions