Iphone 选择UITableView中的所有单元格

Iphone 选择UITableView中的所有单元格,iphone,Iphone,当用户按下工具栏中的按钮时,选择表格(UITableView)中所有单元格的最佳方法是什么?您可以选择调用表格视图的selectRowAtIndexPath方法的单元格: [menuTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop]; 但是,不能在UITableView中选择多个单元格。 如果

当用户按下工具栏中的按钮时,选择表格(UITableView)中所有单元格的最佳方法是什么?

您可以选择调用表格视图的selectRowAtIndexPath方法的单元格:

[menuTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
但是,不能在UITableView中选择多个单元格。
如果要显示和处理单元格的开/关状态,应使用带有UITableViewCellAccessoryCheckmark类型的附件视图的单元格。(有关详细信息,请参阅文档)

我自己还没有尝试过,但请尝试以下方法:

在按钮操作中,循环遍历indexPath并调用它:

for (i = 0; i < [tableView numberOfSections]; i++) {
    for (j = 0; j < [tableView numberOfRowsInSection:i]; j++) {
         indexPath.row = j;
         indexPath.section = i;
         [tableView selectRowAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition];
    }
}
for(i=0;i<[tableView numberOfSections];i++){
对于(j=0;j<[表视图行数部分:i];j++){
indexath.row=j;
indexath.section=i;
[tableView selectRowAtIndexPath:indexPath动画:动画滚动位置:滚动位置];
}
}

这是我遍历表的方法,效果很好

for (int i = 0; i < [ptableView numberOfSections]; i++) {
    for (int j = 0; j < [ptableView numberOfRowsInSection:i]; j++) {
        NSUInteger ints[2] = {i,j};
        NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:ints length:2];
            UITableViewCell *cell = [ptableView cellForRowAtIndexPath:indexPath];
           //Here is your code

    }
}
for(int i=0;i<[ptableView numberOfSections];i++){
对于(int j=0;j<[ptableView numberofrowsin节:i];j++){
nsu整数int[2]={i,j};
nsindepath*indepath=[nsindepath indexpathwithindex:ints length:2];
UITableViewCell*cell=[ptableView cellForRowAtIndexPath:indexPath];
//这是你的密码
}
}

这可以选择表视图中的所有行:

for (NSInteger s = 0; s < self.tableView.numberOfSections; s++) {
        for (NSInteger r = 0; r < [self.tableView numberOfRowsInSection:s]; r++) {
            [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]
                                        animated:NO
                                  scrollPosition:UITableViewScrollPositionNone];
        }
    }
for(NSInteger s=0;s
选择每个新单元格时-从以前的单元格中选择已删除。您无法在UITableView中获得多个选择。我想知道您是否可以在tableView:WillDeceloseRowAtIndexPath:delegate方法中拒绝取消选择。(如果不想取消选中该行,则返回nil。)我也不为任何一个工作。无论如何,主要的一点(imo,但在HIG中找不到确切的位置)是,您不应该一次选择多个单元格,并且选择状态不能是持久的-您可以选择表单元格来执行某些操作。您应该使用单元格的复选标记附件视图来更改/显示单元格状态。我猜解决方案是在内部保留每个选择(正如您在回答中所说的),并相应地为单元格着色,以指示不同类型的选择(或使用复选标记)。您的使用案例是什么?如果您试图保留表行选择,请注意,如果您这样做,应用商店将拒绝您。如果表视图允许多重选择,您可以选择多个单元格。@titaniumdecoy,您是对的。不幸的是,该功能在2009年不可用)请记住将
UITableViewScrollPosition
设置为
。无