开发者

Multiple Value Selection / Deselection in iPhone

I have multiple values for user selection.

When user selects multiple options then it should be saved in the array.

When 开发者_StackOverflow中文版user deselects the value then it should remove the same from the array.

How can it be done?

There can be any random selection and deselection from the options.

How can it be done?


Assuming that you want to do this using a table view, you can maintain an mutable array of selected index paths. You can set accessory type to check mark to indicate selection.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if ( [array indexOfObject:indexPath] == NSNotFound ) {
        [array addObject:indexPath];
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        [array removeObject:indexPath];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
}

and use the array to set the accessoryType properly during cell initialization.


Create a Model class named Options and place all your options as member variables. Update these variables when a user changes the value for any option. Use this variable to port your data from one object to other. Hope this will help you. If it is necessary for you to store the values in a Array then give me some more details about your requirement so we can think further.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜