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 entrie开发者_运维问答s 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..
To show the checkmark:
cell.accessoryType = UITableViewCellAccessoryCheckmark
To clear the checkmark:
cell.accessoryType = UITableViewCellAccessoryNone
You can toggle this easily by testing the current value.
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.
}
}
精彩评论