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 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?

Answers


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.


Need Your Help

Eonasdan Bootstrap datetimepicker is not working

model-view-controller layout view

In my _Layout view I have this as scripts (also CSS have been added):

C++: Infinite loop with a simple menu selection

c++ stdin infinite-loop

The script I am working on is over a page long, so I am going to link it (one simple file):

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.