简体   繁体   English

如何在UISplitView的UITableView子视图中进行多行选择?

[英]How to make multiple rows selection in UITableView subview of UISplitView?

I want to make multiple rows selection in uitableview(uipopover view) which is subview of UISplitview. 我想在uitableview(uipopover视图)中进行多行选择,这是UISplitview的子视图。 The selected rows info should be displayed in Lable in detail pane of splitview. 选定的行信息应显示在splitview的详细信息窗格中的Lable中。

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, 谢谢,

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? 有很多方法可以填充tableView所以我们应该怎么知道你是怎么做到的?

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 (eg selected ). 您将需要具有当前选择的数组或 - 如@RicardPérezdelCampo建议的那样 - 您向数据模型添加属性,其中包含状态(例如, selected )。

Step 2 you will check this property (or array) every time you 第2步,每次你都会检查这个属性(或数组)
a) change the selection OR a)改变选择OR
b) the tableView is displayed on screen ( viewWillAppear and popup appear) b) tableView显示在屏幕上( viewWillAppear和popup出现)

Therefore you need a dataSource which is available from all places (in your case the Popover , the splitView and a detailView ) 因此,您需要一个可从所有位置获得的dataSource(在您的情况下是PopoversplitViewdetailView

You said one tableView already work so the problem for the second is probably the selection dataSource . 你说一个tableView已经工作了,所以第二个问题可能是选择dataSource
There is also a method in UITableView called indexPathsForSelectedRows which will give you an array for the current selection. UITableView还有一个名为indexPathsForSelectedRows的方法,它将为您提供当前选择的数组。 You could apply that selection to the other tableView but it's a hackish way and you should definitely change your data-model instead. 您可以将该选择应用于其他tableView但这是一种hackish方式,您肯定应该改变您的数据模型。

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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM