Conditional Destination View Controller from Secti

2019-06-06 23:00发布

问题:

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.

回答1:

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.



回答2:

You can do it programatically. In the storyboard, draw your two segues from the view controller (rather than from the cell). Then in didSelectRowAtIndexPath, do something like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        [self performSegueWithIdentifier:@"SegueForSection1" sender:indexPath];
    } else if (indexPath.section == 1) {
        [self performSegueWithIdentifier:@"SegueForSection2" sender:indexPath];
    }
}