Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

objective c - iOS: I am trying to send the selected rows(data) to another controller.

I have a tableview for which I am using

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath        *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}

I have an NSArray *selectedDiscounts which I have assigned like this

selectedDiscounts = [self.tableView indexPathsForSelectedRows];

I have to pass the selected table rows data to another controller where I will be populating the tableView with selected rows.

The problem is selectedDiscounts either holds only selected indexPaths and not the data? because of which it shows me the number of objects that are selected but not the data for those selected cells.

I want to store the selected rows data into an NSArray variable. Is that possible? Thanks guys.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to iterate through all of your index paths and get the data yourself.

NSMutableArray *array = [[NSMutableArray alloc] init];

for (NSIndexPath *indexPath in selectedDiscounts) {
    // Assuming self.data is an array of your data
    [array addObject: self.data[indexPath.row]];
}

Now you have your NSArray that contains your data that can you pass to your next controller.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...