3

I want to make multiple rows selection in uitableview(uipopover view) which is subview of UISplitview. The selected rows info should be displayed in Lable in detail pane of splitview.

I have managed to get multiple rows selection but not getting to display the selected rows info in detail pane.

Any help/snippet code would be appreciated.

Thanks,

Ronak
  • 974
  • 6
  • 14
  • if possible then provide code, how to try to manage multiple selection of tableview`s cell ? and how to set detail pane`s label accordingly that selection ? so, anyone got problem... – AJPatel May 29 '12 at 06:34
  • Why don't you just change your data-model state when selecting a row in order to know which cells are selected so the cellForRow method will know which ones has to display as selected? Then you could also add them to an array (or just iterate over your own data model array and check for that state) to display the selected ones info on your detail pane. – Ricard Pérez del Campo Jun 01 '12 at 14:24
  • @phix type in keyword "UISplitViewController" in xcode right click on it and select "jump to definition" you will see the class. – Ronak Jun 07 '12 at 14:18
  • @Ronak em, of course I know about UISplitViewController, but thats a view controller and you can't add subviews to it. As I said please rephrase the question and describe exactly what you want. – Felix Jun 07 '12 at 14:46

2 Answers2

1

since you don't give us some sample code we cannot provide you exact snippets. There are plenty ways to fill a tableView so how should we know how you did that?

Nonetheless I will tell you how it should work abstractly. You will need either an array with the current selection or - as @ Ricard Pérez del Campo suggested - you add a property to your data-model which contains the state (e.g. selected).

Step 2 you will check this property (or array) every time you
a) change the selection OR
b) the tableView is displayed on screen (viewWillAppear and popup appear)

Therefore you need a dataSource which is available from all places (in your case the Popover, the splitView and a detailView)

You said one tableView already work so the problem for the second is probably the selection dataSource.
There is also a method in UITableView called indexPathsForSelectedRows which will give you an array for the current selection. You could apply that selection to the other tableView but it's a hackish way and you should definitely change your data-model instead.

1

In the table view controller add this code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.allowsMultipleSelection = YES;
}

In the table view delegate add this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *selectedRows = [tableView indexPathsForSelectedRows];

    NSMutableArray *mySelectedObjects = [NSMutableArray array];

    for (NSIndexPath *indexPath in selectedRows) {
        MyObject *object = [datasource objectAtIndex:indexPath.row];
        [mySelectedObjects addObject:object];
    }

    [self showSelectedObjectsInDetailPane];
}
3lvis
  • 4,190
  • 1
  • 30
  • 35