Search code examples
iosuitableviewios6uistoryboardsegue

Conditional Destination View Controller from Sections in UITableView


Code in TableView Controller

if ([segue.identifier isEqualToString:@"showListFiles"]) {

    NSIndexPath *ip = [self.tableView indexPathForSelectedRow];

    if (ip.section == 0) {
        NSDictionary *currentBill = [[_response objectForKey:@"facturas_pendientes"] objectAtIndex:ip.row];
        DkBPaymentViewController *pvc = [[DkBPaymentViewController alloc] init];
        pvc = (DkBPaymentViewController *) segue.destinationViewController;
        pvc.setUp = currentBill;
    }
    else if(ip.section == 1){
        DkBBillsFileTableViewController *ftvc = segue.destinationViewController;
        ftvc.filesList = [[[_response objectForKey:@"facturas_pagadas"] objectAtIndex:ip.row] objectForKey:@"archivos_facturas"];
    }

}

Error

-[DkBBillsFileTableViewController setSetUp:]: unrecognized selector sent to instance 0x85a3b00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DkBBillsFileTableViewController setSetUp:]: unrecognized selector sent to instance 0x85a3b00'

How can you do or what is the best way to conditional segue to different view controllers based on the section of the section of the table (Section 1 To pay / Section 2 Paid) ?

Details

DkbPaymentViewController has it's own xib given that I can't make the prototype cell to point to two different

DkBBillsFileTableViewController is the original segue that I declared

Thank you so much in advance, I believe that to find a good method of conditional segue in a tableview would benefit all.


Solution

  • You should setup 2 different cells, each linked to different segues (so they have different identifiers), and each pointing to different view controllers. This will make your code trivial, prevent confusion between classes and use segues as they are intended.