English 中文(简体)
选择所有选定的细胞价值
原标题:Getting all the selected cells values

My purpose is when the user click on a button in view1 (to go to the view2), i will send all the selected cells from UITableView just checked in view1 to the view2. So before passing the table to next view, i wanted to test if i am on the right track, but seems not. This is my code:

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


}

This always returning me a single 0.

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

Although i selected several items on the table.

最佳回答

<代码>mesChosed中的物体:NSIndexPath。 页: 1 类似财产:

-(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);
    }
}
问题回答

首先,NSIndexPath不是惯用的,它是一个带有行文和分立方法的物体,因此,这很可能是你获得零的原因。 你们是否相信你们有“标准”?

If you are not getting index values then best approach wound be as below to access index number:

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




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签