开发者

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

开发者 https://www.devze.com 2023-01-19 17:24 出处:网络
i am new to iphone development.. i am making an application in which table view list the names of countries... userhas to select one or more countries at a time..i want to display the checkmark disclo

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

精彩评论

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

关注公众号