获取所有选定的单元格值

时间:2012-01-13 16:20:09

标签: ios uitableview

我的目的是当用户点击view1中的按钮(转到view2)时,我将发送UITableView刚刚检查过view1的所有选定单元格到view2。 所以在将表格传递到下一个视图之前,我想测试一下我是否在正确的轨道上,但似乎没有。这是我的代码:

-(IBAction)goToView2{
    //get all section selectioned items into an array
    themesChosed=[tView indexPathsForSelectedRows];//tView is the outlet of my UITableView and themesChosed is an NSArray declared in the .h file
    for (int i=0; i<=[themesChosed count]; i++) {
        NSLog(@"%i",[[themesChosed objectAtIndex:i]integerValue]);
    }


}

这总是给我一个0。

2012-01-13 15:52:06.472 MyApp[876:11603] 0

虽然我在桌子上选了几个项目。

3 个答案:

答案 0 :(得分:5)

themesChosed中的对象是NSIndexPath个对象。您需要访问rowsection属性,如下所示:

-(IBAction)goToView2{
    //get all section selectioned items into an array
    themesChosed=[tView indexPathsForSelectedRows];//tView is the outlet of my UITableView and themesChosed is an NSArray declared in the .h file
    for (int i=0; i<=[themesChosed count]; i++) {
        NSIndexPath *thisPath = [themesChosed objectAtIndex:i];
        NSLog(@"row = %i, section = %i", thisPath.row, thisPath.section);
    }
}

答案 1 :(得分:2)

第一个NSIndexPath不是整数,它是一个带有行和节方法的对象,所以这可能就是为什么你得零。您确定allowsMultipleSelection设置为YES吗?

答案 2 :(得分:0)

如果您没有获得索引值,那么最好接近伤口如下,以获取索引号:

  NSArray *indexes = [self.tableView indexPathsForSelectedRows];
   for (NSIndexPath *path in indexes) {
     NSUInteger index = [path indexAtPosition:[path length] - 1];
     [selectedOptionsArray addObject:[optionHolderArray objectAtIndex:index]];
  } 
相关问题