开发者

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 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.
            }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜