0
votes

I am having such an issue right now. I have a UIViewController that has a UITableView, I have it set up so that when the UITableView is in editing mode it returns 3 - circles with the check marks. My UITableView has custom cells with in image and text. When I put the UITableView in edit mode, I am trying to pass an array of the images from multiple selected rows to a second view controller to use those images in a collection view, but I am just having a hard time passing the array of images. Any suggestions would be appreciated.

here is my TableView code:

-(void)didTapEditBUtton:(id)sender{
if ([self.ribbonTableView isEditing]) {
    viewButton.hidden = YES;
    headerLabel.hidden = NO;
    [ribbonTableView setEditing:NO animated:YES];
    [selectButton setTitle:@"select"];
}
else {
    [selectButton setTitle:@"Cancel"];
    // Turn on edit mode
    headerLabel.hidden = YES;
    viewButton.hidden = NO;
    [ribbonTableView setEditing:YES animated:YES];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection   (NSInteger)section{
    return [ribbonsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RibbonCustomCell *cell = (RibbonCustomCell *) [ribbonTableView dequeueReusableCellWithIdentifier:@"RibbonDetail"];

    if (cell != nil)
    {
        RibbonsInfo *ribbonsInfo = [ribbonsArray objectAtIndex:indexPath.row];

    //NSLog(@"%@", ribbonsInfo);

    //Ribbon Image
        cell.ribbonImageView.image = ribbonsInfo.ribbonImage;
        cell.ribbonLabel.text = ribbonsInfo.ribbonName;
    }
    return cell;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 3;
}

-(void)tableView:(UITableView *)tableView didSelectRowsAtIndexPath:(NSIndexPath *)indexPath{


}

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{

}
1
You need to provide more information, code you have tried, images of what is seen etc. - Rohit Gupta
I updated my comment with my tableview code. I have tried making an array NSArray *passArray = [ribbonTableView indexPathsForSelectedRows] and then passing that array to a second view controller but nothing. - Kevin O'Toole

1 Answers

1
votes

You should take the property of NSMutableArray...

@property (nonatomic, strong) NSMutableArray *selectedImages;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.selectedImages = [NSMutableArray new];
}

now when you select or deselect the cell the delegates are called -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@",indexPath);
    RibbonsInfo *ribbonsInfo = [ribbonsArray objectAtIndex:indexPath.row];
    [self.selectedImages addObject:ribbonsInfo.ribbonImage];

}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@",indexPath);
       if (self.selectedImages.count > 0) {
        [self.selectedImages removeObjectAtIndex:indexPath.row];
       }
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 3;
}

Now the selectedImages array contains the selected cell images and you can pass this array. Hope it will solve your problem.